pg_dump -h localhost -U postgres -d appdb -F c -f appdb.dumpSee summary for usage details.
pg_dump, pg_restore, pg_dumpall, pg_basebackup, COPY, and migration workflows.
Core backup and restore commands used constantly.
pg_dump -h localhost -U postgres -d appdb -F c -f appdb.dumpSee summary for usage details.
Create a directory-format dump that supports parallel restore.
pg_dump -h localhost -U postgres -d appdb -F d -j 4 -f /backups/appdb_dirSee summary for usage details.
pg_dump -h localhost -U postgres -d appdb -F p -f appdb.sqlSee summary for usage details.
pg_dump -h localhost -U postgres -d appdb --schema-only -f schema.sqlSee summary for usage details.
pg_dump -h localhost -U postgres -d appdb --data-only -f data.sqlSee summary for usage details.
Restore a custom or directory archive into a database.
pg_restore -h localhost -U postgres -d appdb appdb.dumpSee summary for usage details.
Drop objects before recreating them during restore.
pg_restore -h localhost -U postgres -d appdb --clean --if-exists appdb.dumpSee summary for usage details.
psql -h localhost -U postgres -d appdb -f appdb.sqlSee summary for usage details.
Commands for globals, all databases, and upgrades.
pg_dumpall -h localhost -U postgres --globals-only > globals.sqlSee summary for usage details.
pg_dumpall -h localhost -U postgres > cluster.sqlSee summary for usage details.
Take a physical base backup suitable for replication or disaster recovery.
pg_basebackup -h primary-db -U replicator -D /backups/base -Fp -Xs -PSee summary for usage details.
pg_verifybackup /backups/baseSee summary for usage details.
pg_upgrade --check -b /usr/lib/postgresql/17/bin -B /usr/lib/postgresql/18/bin -d /var/lib/postgresql/17/data -D /var/lib/postgresql/18/dataSee summary for usage details.
pg_upgrade -b /usr/lib/postgresql/17/bin -B /usr/lib/postgresql/18/bin -d /var/lib/postgresql/17/data -D /var/lib/postgresql/18/dataSee summary for usage details.
Collect statistics after a fresh restore or upgrade.
vacuumdb --all --analyze-in-stagesSee summary for usage details.
Dump or restore individual schemas, tables, and objects.
pg_dump -h localhost -U postgres -d appdb -t public.users -f users.sqlSee summary for usage details.
pg_dump -h localhost -U postgres -d appdb -n accounting -f accounting.sqlSee summary for usage details.
pg_restore -l appdb.dumpSee summary for usage details.
pg_restore -h localhost -U postgres -d appdb -t public.users appdb.dumpSee summary for usage details.
pg_restore -h localhost -U postgres -d appdb --schema-only appdb.dumpSee summary for usage details.
pg_restore -h localhost -U postgres -d appdb --data-only appdb.dumpSee summary for usage details.
Restore using multiple worker jobs when archive format allows it.
pg_restore -h localhost -U postgres -d appdb -j 4 appdb.dumpSee summary for usage details.
Fast data movement into and out of PostgreSQL.
COPY public.users TO '/var/lib/postgresql/users.csv' CSV HEADER;Requires superuser or suitable permissions.
COPY public.users (user_id, email, created_at)
FROM '/var/lib/postgresql/users.csv' CSV HEADER;See summary for usage details.
Export via the client machine rather than the database server.
\copy public.users TO './users.csv' CSV HEADERSee summary for usage details.
\copy public.users (user_id, email, created_at) FROM './users.csv' CSV HEADERSee summary for usage details.
COPY (SELECT * FROM public.users) TO PROGRAM 'gzip > /tmp/users.csv.gz' CSV HEADER;See summary for usage details.
Load immutable initial data into a newly created or truncated table.
COPY staging_import FROM STDIN WITH (FORMAT csv, HEADER true, FREEZE true);Useful for bulk-load workflows with certain constraints.