Postgresql mini-cheatsheet.

Quick reference for PG command line tools, this post serve as a reference for future use.

Postgresql command line tools:

– Dump: /PATH/TO/BIN/pg_dump -U USERNAME DATABASE_NAME > DESTINATION.sql;

– Restore: /PATH/TO/BIN/pg_restore -U USERNAME -no-owner -d DATABASE_NAME < file.sql; or /PATH/TO/BIN/psql -U USERNAME DATABASE_NAME < file.sql;
– Connect to PG command line interface : /PATH/TO/BIN/psql --U USERNAME ;
– Exit command line tool: \q

Inside psql command line tool:
– user or connect to database: \connect DATABASE_NAME
– list all databases: \list | \l
– list all tables in the current database: \dt
– describe table structure: \d+ TABLE_NAME
– list all users: \du

Leave a Reply

Your email address will not be published. Required fields are marked *