Skip to content
Latchkey

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.sql

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →