PostgreSQL useful commands

sudo -u postgres psql

list all databases

\l

connect to database xxx

\c xxx

list all tables in the current database

\dt

list all tables and indexes in current database

\d

list column yyy detail

\d yyy

drop table xxx and yyy in current database

drop table xxx, yyy;

drop xxx database

DROP DATABASE "xxx";

show postgres version

select version();

show current database

SELECT current_database();

connection info

\conninfo

exit psql

\q

rename database

ALTER DATABASE oldame RENAME TO newname;

clone database

CREATE DATABASE newdb WITH TEMPLATE originaldb;