Because do not understand PostgreSQL psql tool, after the database is installed directly with the Pgadmin or navicat to connect the operation, in the confirmation of the initialization of the library after the default some things have been nowhere to start, in the case of the PG general system has not been made confused, First of all, the database role can be both a user and the concept of a group, always struggling to query the current operation is which library which table, which mode of the state, even the table structure do not know how to see. Then still take the time to learn the basic elements of PG, mainly because of MySQL's generational relationship, the two have similar places, but in the management system is not the same. Finally, the first return to the server side, directly with Psql to operate first, to understand the psql defined meta-commands, easy to learn to learn.
Build new roles and libraries
Login ' 111111 ' ; CREATE ROLE
postgres=# Create Database Yun owner Chen;
CREATE DATABASE
Switch the role, after switching the prompt also from # into the superuser;
postgres=# \c- Chen; SSL connection (encryption: DHE"postgres" "Chen".
Postgres=>
Switch libraries
Postgres=> \c Yun;
)
" Yun " " Chen ".
Yun=>
New mode
Yun=> Create Schema Yun; CREATE SCHEMA
Here is a new table if the mode is not specified by default in which mode of the problem, different modes of different tables can be the same name, the \d command is also from the face of the schema names to get what table
Yun=>show Search_path;
Search_path
----------------
"$user", public
Yun=> set Search_path to Yun,"$user", public; SET
Yun=> show Search_path; Search_path ----------------------"$user", Public (1 rows)
When set, the new table is automatically returned to the Yun mode, and a new table is created.
yun=> CREATE TABLE website (Yun (int primary Key,yun (> name varchar (255 Null, Yun (> URL varchar (255null, Yun (null) Yun- ;
The copy command requires Superuser to import data from a file that has been exported from MySQL in advance, but Psql provides another way to guide the data
' /var/lib/mysql/yun/src_data/allwebsite.dat ' ' , ';
Modify, add a new field
Yun=> ALTER TABLE website add column tm_update timestamp (0timenull default now (); ALTER TABLE
postgresql-user, library, mode, table