pg_dump
TLDR
Dump a database
SYNOPSIS
pg_dump [options] [dbname]
DESCRIPTION
pg_dump is a utility for backing up PostgreSQL databases. It creates a consistent snapshot of the database at the time the dump begins, even while the database is being used.
The output can be in SQL script format (plain text) or custom archive formats that support compression and parallel restore. SQL scripts can be restored with psql, while archive formats use pg_restore.
pg_dump does not block readers or writers during the dump, making it suitable for production backups.
PARAMETERS
-F format
Output format (p=plain, c=custom, d=directory, t=tar).-f file
Output file or directory.-t table
Dump specific table(s).-T table
Exclude table(s).-n schema
Dump specific schema(s).-N schema
Exclude schema(s).-s, --schema-only
Dump schema only, no data.-a, --data-only
Dump data only, no schema.-c, --clean
Include DROP commands.-C, --create
Include CREATE DATABASE command.-j jobs
Parallel dump jobs (directory format).-h host
Database server host.-p port
Database server port.-U user
Connect as user.-W
Force password prompt.-Z level
Compression level (0-9).
CAVEATS
Does not dump roles and tablespaces (use pg_dumpall). Plain format cannot be restored in parallel. Custom format recommended for large databases. May require significant disk space for large databases.
HISTORY
pg_dump has been part of PostgreSQL since its earliest releases, evolving from the original POSTGRES project at UC Berkeley in the 1980s. It has gained features like parallel dump, custom archive format, and selective backup options as PostgreSQL evolved into a major database system.
SEE ALSO
pg_restore(1), pg_dumpall(1), psql(1), createdb(1)


