DBAtlas · 数据库运维图谱

使用 pgBackRest 还原最新备份

PostgreSQL备份与 PITR

命令

# 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

作用

还原最新备份并写入 recovery.signal 和 restore_command;启动时 PostgreSQL 回放所有已归档的 WAL 到最近的一致点,并在新的 timeline 上提升。

适用场景

当主库的数据目录丢失/损坏时,或定期测试备份可还原性时。

注意

如果还原出的集群和旧集群同时归档到同一个 stanza,存储库会损坏;测试还原请使用 --archive-mode=off。在 Patroni 下,请先 pause 集群或停止 Patroni,否则 Patroni 会干预。如果存在 PGDATA 之外的表空间或路径,请检查 --tablespace-map 和 link 选项。

在 DBAtlas 中打开 →

相关内容