Postgres 归档没有按预期运行,有人有什么建议吗?

Postgres archiving is not functioning as intended, anyone have any suggestions?

我在两台服务器之间设置了流式传输 master/slave,并且工作正常。存档部分是一半工作。它只是不断创建存档,不会删除旧的。谁能提出解决方案?

我已经尝试了全新的基础备份并重新启动流式传输等。但是我在日志中不断收到以下错误:

2019-08-27 07:13:14 +08  DETAIL:  The failed archive command was: test ! -f /var/lib/pgsql/data/pg_xlog/000000010000028000000068 && cp pg_xlog/000000010000028000000068 /var/lib/pgsql/data/pg_xlog/000000010000028000000068
2019-08-27 07:13:15 +08  LOG:  archive command failed with exit code 1
2019-08-27 07:13:15 +08  DETAIL:  The failed archive command was: test ! -f /var/lib/pgsql/data/pg_xlog/000000010000028000000068 && cp pg_xlog/000000010000028000000068 /var/lib/pgsql/data/pg_xlog/000000010000028000000068
2019-08-27 07:13:15 +08  WARNING:  transaction log file "000000010000028000000068" could not be archived: too many failures

我已经检查过,文件在那里:

-rw------- 1 postgres postgres 16777216 Aug 27 06:44 000000010000028000000068

存档状态:

-rw------- 1 postgres postgres 0 Aug 27 06:44 000000010000028000000068.ready

Postgres 版本为 9.2.23。不幸的是,升级不是一种选择。

这是主配置的存档部分:

# - Archiving -

archive_mode = on       # allows archiving to be done
                                # (change requires restart)
#archive_command = '/bin/true'          # Used for trouble shooting archiving to temporarily start postgres.
archive_command = 'test ! -f /var/lib/pgsql/data/pg_xlog/%f && cp %p /var/lib/pgsql/data/pg_xlog/%f'            # command to use to archive a logfile segment
                                # placeholders: %p = path of file to archive
                                #               %f = file name only
                                # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
#archive_timeout = 0            # force a logfile segment switch after this
                                # number of seconds; 0 disables

这是 recovery.conf 从站上的一部分:

restore_command = 'cp -p /var/lib/pgsql/data/pg_xlog/%f %p'
trigger_file = '/var/lib/pgsql/i_am_master.pg.trigger'
recovery_target_timeline = 'latest'
archive_cleanup_command = 'pg_archivecleanup /var/lib/pgsql/data/pg_xlog %r'

还有什么需要检查的吗?

由于您没有从 cp 收到错误消息,archive_command 失败的部分可能是

test ! -f /var/lib/pgsql/data/pg_xlog/%f

这意味着存档中已经有同名文件。

调查文件是如何到达那里的,如果安全则将其删除,然后 WAL 归档将恢复工作。

测试是为了避免意外覆盖其他人存档的 WAL 文件。


您的存档目录的名称听起来像是您正试图直接存档到另一个集群的 pg_xlog 目录中。那不行。您需要一个共享目录 — 一个集群归档到它,另一个从它恢复。