Quickly rebuild a standby with pgBackRest delta restore
PostgreSQLBackup & PITRCommand
sudo systemctl stop postgresql-16
# Keeps the existing PGDATA and fetches only differing files; writes standby.signal:
sudo -u postgres pgbackrest --stanza=<stanza> --delta --type=standby "--recovery-option=primary_conninfo=host=<primary_host> port=5432 user=replicator application_name=<standby_name>" restore
sudo systemctl start postgresql-16
psql -X -c "SELECT status, sender_host FROM pg_stat_wal_receiver;"What it does
--delta compares files in the existing PGDATA with the backup (size/timestamp and checksum) and copies only the differing ones; --type=standby writes standby.signal and recovery-option adds primary_conninfo. The standby first catches up from the archive, then switches to streaming.
When to use it
To turn a lagging or timeline-diverged standby, or an old primary where pg_rewind failed, back into a replica without a full copy.
Caution
Delta replaces/removes differing or extra files in the target directory with the backup's; running it on the wrong server destroys that server's data. pgBackRest refuses to restore over a running PostgreSQL, but verify yourself that the service is stopped. Keep the password in .pgpass rather than in primary_conninfo.
Related
- Configure WAL archiving for pgBackRest (archive-push/archive-get)
- Create the pgBackRest stanza and verify archiving (stanza-create/check)
- Take full, differential and incremental backups with pgBackRest
- Show the pgBackRest backup catalog and WAL archive range (info)
- Restore the latest backup with pgBackRest
- Restore to a point in time with pgBackRest (PITR, --type=time)