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
- PostgreSQL18.6-0ubuntu0.26.04.1
- wal_levelreplica
- TimeAbout 14 min
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 |
This guide includes
Use this before relying on a pg_dump backup. This matters because it backs up one database and not the roles that own it - so a restore onto a fresh server fails on things the dump never contained.
- recording what you expect to get back, by counting first
- taking the dump, and looking inside what it produced
- finding what the dump does not contain, which is the step that saves a restore
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