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を最新の一貫性のある時点まで再生し、新しいタイムラインで昇格する。

使用する場面

プライマリのデータディレクトリが失われた/破損したとき、またはバックアップがリストア可能であることを定期的にテストするときに。

注意

リストアしたクラスタと旧クラスタが同時に同じstanzaにアーカイブすると、リポジトリが破損する。テストリストアには--archive-mode=offを使用する。Patroni管理下では、先にクラスタをpauseするかPatroniを停止する。そうしないとPatroniが介入する。PGDATA外の表領域やパスが存在する場合は、--tablespace-mapとlinkのオプションを確認する。

DBAtlas で開く →

関連項目