pg_dump Command Reference: Flags, Usage & CI Examples
pg_dump exports a single PostgreSQL database to a script or archive.
pg_dump writes a consistent snapshot of one database as a plain SQL script or a compressed archive that pg_restore can rebuild. It produces the backups and fixtures pipelines reuse.
Common flags and usage
- -F c|d|t|p: output format (custom / directory / tar / plain)
- -f <file>: write output to a file
- -t <table> / -n <schema>: limit to matching tables or schemas
- --no-owner: omit ownership so any role can restore
- --no-acl: omit GRANT/REVOKE statements
- -h/-p/-U/-d and PGPASSWORD: same connection options as psql
Example
shell
PGPASSWORD=${PGPASSWORD} pg_dump -h localhost -U postgres -Fc -d app -f app.dump
PGPASSWORD=${PGPASSWORD} pg_dump -h localhost -U postgres --no-owner app > portable.sqlIn CI
A custom (-Fc) dump must be restored with pg_restore, while a plain dump restores with psql -f. pg_dump refuses to dump from a server newer than the client, so install a postgresql-client at least as new as the service container.
Key takeaways
- pg_dump exports one database as a script (-Fp) or archive (-Fc/-Fd/-Ft).
- Custom-format dumps restore with pg_restore, plain dumps with psql.
- Match the client version to the server to avoid a version mismatch.
Related guides
pg_restore Command Reference: Flags, Usage & CI ExamplesReference for pg_restore: -d, -C, -j, --clean, --no-owner, --exit-on-error, and a CI example that rebuilds a…
psql Command Reference: Flags, Usage & CI ExamplesReference for the psql PostgreSQL client: connection flags, -c and -f, PGPASSWORD, ON_ERROR_STOP, and a CI ex…
createdb Command Reference: Flags, Usage & CI ExamplesReference for createdb: -h, -U, -O, -E, -T, idempotent creation, and a CI example that creates a fresh Postgr…