Logical Backups with pg_dump
A developer runs a migration against production instead of staging and drops the tariffs table. Pedal's cloud host has disk snapshots, but restoring one would roll back the whole server to last night. What you want is last night's copy of one table. That is the job of a logical backup.
The rule
pg_dump saves one database as rebuild instructions, frozen at one moment.
pg_dump connects like any client and writes out what it would take to rebuild one database: CREATE statements for every object, then the data. Three phrases in the rule carry the rules:
- One database. It never includes roles or tablespaces, which belong to the cluster, and never the server's config files.
- Rebuild instructions. Restoring means re-running them: tables are created, rows loaded, indexes rebuilt. That makes dumps portable to a newer major version or another machine, but a restore of a large database is slow.
- Frozen at one moment. The dump reads from a single snapshot, so it is consistent even while the app keeps writing. Thanks to MVCC it does not block normal reads or writes. It does hold light locks that make
ALTER TABLEorDROP TABLEwait until it finishes.
# custom format: compressed, restore selectively with pg_restore
pg_dump -h db1 -U pedal_backup -d pedal -Fc -f pedal-2026-09-25.dump
# directory format, four parallel jobs for a bigger database
pg_dump -d pedal -Fd -j 4 -f pedal-2026-09-25.dir
# plain SQL, readable, restored with psql
pg_dump -d pedal -Fp -f pedal-2026-09-25.sql
# just the schema, or just one table
pg_dump -d pedal --schema-only -f pedal-schema.sql
pg_dump -d pedal -t public.tariffs -Fc -f tariffs.dump| Format | Flag | Restore with | Parallel |
|---|---|---|---|
| Plain SQL | -Fp |
psql |
no |
| Custom | -Fc |
pg_restore |
restore only |
| Directory | -Fd |
pg_restore |
dump and restore |
| Tar | -Ft |
pg_restore |
no |
The dumping role needs to read every object it dumps. The predefined role pg_read_all_data covers table data; alternatively the owner role runs it.