Connect to the database, the default user and database is Postgres
Psql-u user-d dbname
switch databases, equivalent to MySQL's use dbname
\c dbname
Enumerate the databases, equivalent to the MySQL show databases
\l
List table, equivalent to the MySQL show tables
\dt
View table structure, equivalent to desc tblname,show columns from Tbname
\d Tblname
\di View Index
CREATE database:
CREATE DATABASE [DB name];
Delete database:
drop database name];
* Rename a table:  
ALTER TABLE [table name a] rename to [table name b];
* Delete a table:
drop table [table name];
* add field in existing table:  
ALTER TABLE [table name] Add column [Field name] [type];
* Delete field in table:  
Alter Table [table name] Drop column [field name];
* Rename a field:  
ALTER TABLE [table name] Rename column [field name a] to [field name b];
* Give one word Segment Set default value:  
ALTER TABLE [table name] ALTER column [field name] Set default [new default];
* Remove default value:  
ALTER TABLE [table name] ALTER column [Field name] Drop default;
Insert data in table:
insert into table name (Field name m],[field Name N],......) VALUES ([Column M's Value],[column N's value],......);
modifies data for a column of a row in a table:
Update [table name] set [Target Field name]=[target value] where [the row feature];
Delete a row of data from a table:
Delete from [table name] where [the row feature];
Delete from [table name];--delete entire table
CREATE table:
Create tables ([field name 1] [Type 1] <references Associated table name (associated field name) >;,[field Name 2] [type 2],...... <,primary key (field name m, field name N,...) >;);
\copyright display of PostgreSQL usage and release terms
\encoding [character encoding name]
Display or set the user-side character encoding
\h [name] SQL command syntax description, with * Show all commands
\prompt [Text] Name
Prompt user to set internal variables
\password [USERNAME]
Securely change the password for a user
\q Exit Psql
Can be done using pg_dump and Pg_dumpall. For example, back up the sales database:
Pg_dump Drupal>/opt/postgresql/backup/1.bak
Pgsql Common Commands