pg_dump

Back up a PostgreSQL database to a file.

low risk

interactive breakdown — edit the command and press Explain
$ 
What it does

pg_dump creates consistent backups of PostgreSQL databases without locking tables. The custom format (-Fc) is recommended — it supports parallel restore and selective table restoration. For full cluster backups including roles, use pg_dumpall.

Common flags
FlagMeaning
-FcCustom compressed format (best for large DBs)
-FpPlain SQL format (human-readable)
-t --tableDump only specific table
-n --schemaDump only specific schema
-j --jobsParallel dump with N jobs
Examples
pg_dump -h localhost -U postgres -Fc mydb > mydb.dumpFull custom-format backup · explain & risk-check →
pg_dump -h db.prod -U postgres -Fc -t users mydb > users_backup.dumpBack up single table · explain & risk-check →
pg_restore -U postgres -d mydb_restore mydb.dumpRestore from custom format backup · explain & risk-check →
pg_dump -Fc mydb | gzip > mydb_$(date +%Y%m%d).dump.gzCompressed timestamped backup · explain & risk-check →
Pro tip

Use `pg_dump -Fc` (not plain SQL) for production backups — custom format is smaller, supports parallel restore with `pg_restore -j 4`, and allows restoring individual tables.

Related
psql rsync cron
Open the full explainer →More in Databases

Reference text is hand-written and may be incomplete — check man pg_dump for your version. Test destructive commands on a non-production system first.