DBAtlas · Database operations atlas

Restore the latest backup with pgBackRest

PostgreSQLBackup & PITR

Command

# 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-16

What 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.

Open in DBAtlas →

Related