Hands-on Lab·PostgreSQL
PostgreSQL Physical Backups with pg_basebackup
A physical copy of the entire cluster taken over the replication protocol while it runs - every database, every role, ready to start as a server. It is also the first half of both point-in-time recovery and a streaming replica.
Backup and Restore Guide 24 of 47 Intermediate
- OSUbuntu 26.04 LTS
- PostgreSQL18.6-0ubuntu0.26.04.1
- wal_levelreplica
- TimeAbout 15 min
-Xs streams WAL during the backup on a second connection, which is why the result is self-consistent without needing archived WAL to start. It requires a spare max_wal_senders slot.
| 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 when a logical dump is not enough. This matters because pg_basebackup copies the whole cluster over the replication protocol while it is running - which is what a replica, or a point-in-time restore, starts from.
- taking a physical backup of the running cluster, with four flags each doing real work
- looking at the three files it produced
- seeing that this copies the cluster rather than one database
Before you start
- A superuser or a role with
REPLICATION. - Disk space for a full copy of the cluster.
-
Take a physical backup of the running cluster
-
Look at what it produced