DBAtlas · Database operations atlas

Configure WAL archiving for pgBackRest (archive-push/archive-get)

PostgreSQLBackup & PITR

Command

# postgresql.conf (changing archive_mode requires a restart):
wal_level = replica
archive_mode = on
archive_command = 'pgbackrest --stanza=<stanza> archive-push %p'
# On the restore/standby side (in postgresql.conf on PG12+):
restore_command = 'pgbackrest --stanza=<stanza> archive-get %f "%p"'

# /etc/pgbackrest/pgbackrest.conf (database host, local repo example):
[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
archive-async=y
spool-path=/var/spool/pgbackrest
process-max=4
compress-type=zst
start-fast=y

[<stanza>]
pg1-path=/var/lib/pgsql/16/data

What it does

Makes PostgreSQL send every completed WAL segment to the pgBackRest repository (archive-push) and fetch it from there during recovery (archive-get); archive-async makes pushing parallel and asynchronous through a spool directory.

When to use it

As the first step of setting up physical backups and PITR with pgBackRest, before stanza-create.

Caution

As long as archive_command fails, WAL accumulates in pg_wal and the primary stops when the disk fills; monitor pg_stat_archiver.failed_count. With Patroni, set these parameters through patroni.yml / edit-config instead of postgresql.conf. Archiving from two different clusters into the same stanza corrupts the repository.

Open in DBAtlas →

Related