-- into postgrespsql-- show all database/l-- create databaseCREATEDATABASEdbname;
Connect to database
1
psql<dbname>
or
123
psql\l\c<dbname>
Show
12345678
\l-- List databases\dt*.*-- List tables from all schemas\dt-- List current path tables\dn-- List Schema\di-- List Index\dt+-- List Table\d+<tablename>-- List ColumnSELECT*FROM<tablename>-- List Record
Dump db
1
pg_dump<dbname><filename>
Import db
1
psql<filename><<dbname>
Connect to a remote database
1
psql-h<host>-p<port>-U<username>
Create User
123456789101112
createusertestuser-- or--show users\du+CREATEUSER<username>;GRANTALLPRIVILEGESONDATABASE<dbname>TO<username>;GRANTALLPRIVILEGESONTABLE<tablename>TO<username>;-- Allow user1 to set role as user2GRANT<username2>to<username1>;