PostgreSQL: Cheat Sheet

2020, May, 23

DatabasePostgresql
Check postgresql status
systemctl status postgresql
Login as postgres user
sudo su postgres
Create
CREATE DATABASE <database_name>; CREATE USER <username> WITH PASSWORD <password>; ALTER USER <username> WITH SUPERUSER;
  • enter command mode psql
  • list databases \l
  • list all users \du
  • switch database \c
  • list tables \dt
Backup
pg_dump <database_name> > <backup_filename>
Restore
psql <database_name> < <backup_filename>