PostgreSQL
databasepostgresqlReferenceIntermediate
PostgreSQL Database Backup (pg_dump)
Export and backup a PostgreSQL database schema and data to a plain text SQL or custom binary dump.
Verified: 2026-09-30
Tested on:postgres 16.x
Platforms:
linuxmacoswindows
#postgresql#database#backup#pg_dump
Command
pg_dump -U postgres -d my_database -F c -b -v -f my_database_backup.dump
Short Description
pg_dump is an official PostgreSQL utility for creating consistent logical backups of a single database, even while the database is actively being read and written to by clients.
Examples
1. Plain SQL Text Dump (Human Readable)
pg_dump -U postgres -h localhost -d production_db > backup_$(date +%Y%m%d).sql2. Custom Compressed Archive Format (Recommended for Production)
pg_dump -U postgres -h localhost -d production_db -F c -b -v -f backup.dump3. Restore with pg_restore
pg_restore -U postgres -d production_db -v backup.dump