Restore the latest backup with pgBackRest
PostgreSQLBackup & PITRCommand
# PostgreSQL must be stopped and PGDATA empty (otherwise use --delta)
sudo systemctl stop postgresql-16
sudo -u postgres pgbackrest --stanza=<stanza> --log-level-console=info restore
# From a specific backup: --set=<backup_label>
# When restoring to another server for testing, disable archiving:
# sudo -u postgres pgbackrest --stanza=<stanza> --archive-mode=off restore
sudo systemctl start postgresql-16What it does
Restores the latest backup and writes recovery.signal and restore_command; on startup PostgreSQL replays all archived WAL to the most recent consistent point and promotes on a new timeline.
When to use it
When the primary's data directory is lost/corrupted, or when regularly testing that backups are restorable.
Caution
If the restored cluster and the old cluster archive to the same stanza at the same time, the repository is corrupted; use --archive-mode=off for test restores. Under Patroni, pause the cluster or stop Patroni first, otherwise Patroni interferes. If tablespaces or paths outside PGDATA exist, review the --tablespace-map and link options.
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 to a point in time with pgBackRest (PITR, --type=time)
- Quickly rebuild a standby with pgBackRest delta restore