DBAtlas · Database operations atlas

Build a physical replica (pg_basebackup)

PostgreSQLReplication

Command

pg_basebackup -h primary_host -U replicator -D /var/lib/postgresql/16/main -Fp -Xs -P -R --slot=replica_slot_1 -C

What it does

Takes a full physical backup from the primary, streams WAL (-Xs), writes standby.signal and primary_conninfo (-R) and creates the replication slot (-C).

When to use it

To build a new streaming standby (read replica or failover target).

Caution

The target directory (-D) must be empty. On the primary, pg_hba.conf must grant 'replication' access to the replicator user, and there must be sufficient wal_keep_size / a slot. With PostgreSQL 12+, -R produces standby.signal instead of recovery.conf.

Open in DBAtlas →

Related