PostgreSQL Cheat Sheet Query Page

This is a cheat sheet command page for everything related to PostgreSQL Database Server.

List all existing database :

postgres=# \l

or

postgres=# \list

 Quit from PostgreSQL Command Console :

postgres-# \q

or

postgres-# \quit

Create Database :

postgres-# create database db_name

Drop Database :

postgres-# drop database db_name

Restore Database from a plain file backup database :

psql -Upostgres_username db_name < db_dump_file_location_and_name

Restore Database from a PostgreSQL custom-format dump file backup database :

pg_restore -Upostgres_username -d db_name db_dump_file_location_and_name.pgdump

Select and Use Database :

postgres-# \connect db_name

or

postgres-# \c db_name

Show All Tables in a Database :

dbname-# \d

or

dbname-# \dt

Leave a Reply