OnCallReady

Commands

pg_basebackup - take a base backup of a running PostgreSQL server

pg_basebackup [OPTION]...

Options you will use

-D, --pgdata=DIRECTORY
receive base backup into directory (must be empty or not exist).
-F, --format=p|t
output format (plain (default), tar).
-X, --wal-method=none|fetch|stream
include required WAL files with specified method (default stream).
-z, --gzip
compress tar output.
-c, --checkpoint=fast|spread
set fast or spread (default) checkpointing - fast starts at once.
-R, --write-recovery-conf
write configuration for replication (standby.signal + primary_conninfo in postgresql.auto.conf).
-C, --create-slot
create replication slot (with -S).
-S, --slot=SLOTNAME
replication slot to use.
-P, --progress
show progress information.
-v, --verbose
output verbose messages.
-i, --incremental=OLDMANIFEST
take an incremental backup (needs summarize_wal = on).
-h, --host=HOSTNAME
database server host or socket directory (default: the Unix socket in /var/run/postgresql). A value starting with / is a socket directory; anything else is TCP.
-p, --port=PORT
database server port (default 5432).
-U, --username=USERNAME
database user name (default: your OS user name).
-w, --no-password
never prompt for a password (fail instead: what scripts want).
-W, --password
force a password prompt (normally automatic).

Examples

$ pg_basebackup -D /backup/base -Fp -X stream -c fast -P

a base backup for PITR

$ pg_basebackup -h primary -U replicator -D /var/lib/postgresql/18/replica -R -C -S replica1 -X stream -P

a new replica with its own slot

Taught in

Try pg_basebackup in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.