Hands-on Lab·PostgreSQL
PostgreSQL Logical Backups with pg_dump
`pg_dump` backs up one database and **not** the roles that own it - the dump contains zero `CREATE ROLE` statements. Restoring onto a fresh server fails on every GRANT until you have also run `pg_dumpall --roles-only`.
Backup and Restore Guide 21 of 47 Beginner
- OSUbuntu 26.04 LTS (resolute)
- PostgreSQL18.6-0ubuntu0.26.04.1
- wal_levelreplica
- TimeAbout 14 min
- Reviewed27 August 2026
Written against the versions above. `pg_dump` is consistent without locking - it uses a snapshot, so a dump of a live database reflects one moment and blocks nothing. There is no flag to remember, unlike MySQL's `--single-transaction`.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
Before you start
- The
appdbdatabase with data and asalesschema.
-
Record what you expect to get back
-
Take the dump and look inside it
-
Find what the dump does not contain