PostgreSQL 9.2 归档恢复后最后重放的 WAL

Posted

技术标签:

【中文标题】PostgreSQL 9.2 归档恢复后最后重放的 WAL【英文标题】:PostgreSQL 9.2 archiving last replayed WAL after recovery 【发布时间】:2013-07-03 09:28:34 【问题描述】:

按照 PostgreSQL 9.2 官方文档,我在我的 postgres.conf 文件中设置了连续归档:

wal_level = archive
archive_mode = on
archive_command = 'test ! -f /.../archive/%f && cp %p /.../archive/%f'

成功备份和恢复后,启动数据库时归档命令失败,因为 PostgreSQL 正在尝试归档最后重放的 WAL 文件,显然它已经被归档。我的 recovery.conf 文件如下:

restore_command = 'cp /.../archive/%f "%p"'
recovery_target_time = '2013-07-02 15:20:12'

这是我尝试启动数据库时遇到的错误:

LOG:  database system was interrupted; last known up at 2013-07-02 14:53:37 CEST
LOG:  creating missing WAL directory "pg_xlog/archive_status"
LOG:  starting point-in-time recovery to 2013-07-02 15:20:12+02
LOG:  restored log file "000000010000000000000002" from archive
LOG:  redo starts at 0/2000020
LOG:  consistent recovery state reached at 0/20023D0
LOG:  restored log file "000000010000000000000003" from archive
LOG:  recovery stopping before commit of transaction 4063, time 2013-07-02 15:20:12.211559+02
LOG:  redo done at 0/306D8B8
LOG:  last completed transaction was at log time 2013-07-02 15:20:11.189978+02
cp: cannot stat `/.../archive/00000002.history': No such file or directory
LOG:  selected new timeline ID: 2
cp: cannot stat `/.../archive/00000001.history': No such file or directory
LOG:  archive recovery complete
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections
LOG:  archive command failed with exit code 1
DETAIL:  The failed archive command was: test ! -f /.../archive/000000010000000000000003 && cp pg_xlog/000000010000000000000003 /.../archive/000000010000000000000003
LOG:  archive command failed with exit code 1
DETAIL:  The failed archive command was: test ! -f /.../archive/000000010000000000000003 && cp pg_xlog/000000010000000000000003 /.../archive/000000010000000000000003
LOG:  archive command failed with exit code 1
DETAIL:  The failed archive command was: test ! -f /.../archive/000000010000000000000003 && cp pg_xlog/000000010000000000000003 /.../archive/000000010000000000000003
WARNING:  transaction log file "000000010000000000000003" could not be archived: too many failures

这是预期的行为吗?最后重放的 WAL 文件是否应该在恢复后存档?如果是这样,如果文件已经归档(如文档中所述),归档命令不应失败。

【问题讨论】:

【参考方案1】:

显然,您应该只存档一次并恢复存档的副本。

我会在恢复期间关闭存档,然后再打开它。

【讨论】:

以上是关于PostgreSQL 9.2 归档恢复后最后重放的 WAL的主要内容,如果未能解决你的问题,请参考以下文章

CUDA 中指令重放的其他原因

如何查看 GDB 存储的用于记录/重放的执行日志?

如何将 API 重放的 JSON 中的值放到另一个 API 发布方法的主体中?

PostgreSQL启动恢复期间,恢复到的时间线的确定

PostgreSQL 8.4 和 9.3

pg_restore - 从一个由 pg_dump 创建的备份文件中恢复 PostgreSQL 数据库。