Last Updated: October 10, 2016
·
306
· debbora

Postgres Cheatsheet

Access

sudo su - postgres
psql -U postgres -d postgres

or

sudo -u postgres psql -U postgres -d postgres

Command lines

\list or \l: list all databases

\connect databasename or \c databasename

\dt: list all tables in the current database

Backup: pgdump databasename > backup_file.bak

Restore: psql emptydatabasename < backup_file.bak

References: https://www.digitalocean.com/community/tutorials/how-to-backup-postgresql-databases-on-an-ubuntu-vps