PostgreSQL 流复制损坏:无效幻数,乱序时间线 ID

Kaj*_*nus 6 postgresql replication

出于某种原因,我的 PostgreSQL 从站不再流式复制主站上的更改。之前可以用,有段时间了,最​​近发现slave的数据库内容很旧,slave的日志文件有错误,分别是“无效幻数0000 ”和“乱序时间线ID 1(之后2) ”。

你知道我该如何解决这个问题吗?或者为什么会发生?

详情如下。

日志文件错误消息:(在从站上,pg_log/postgresql-Sat.log)

LOG:  entering standby mode
LOG:  redo starts at 0/1C78848
LOG:  consistent recovery state reached at 0/1C7FA30
LOG:  database system is ready to accept read only connections
LOG:  invalid magic number 0000 in log file 0, segment 1, offset 14942208
LOG:  streaming replication successfully connected to primary
LOG:  out-of-sequence timeline ID 1 (after 2) in log file 0, segment 1, offset 0
FATAL:  terminating walreceiver process due to administrator command
LOG:  out-of-sequence timeline ID 1 (after 2) in log file 0, segment 1, offset 0
LOG:  out-of-sequence timeline ID 1 (after 2) in log file 0, segment 1, offset 0
LOG:  out-of-sequence timeline ID 1 (after 2) in log file 0, segment 1, offset 0
...
Run Code Online (Sandbox Code Playgroud)

事务日志:(从服务器上——很奇怪,日志文件 0...2... 1来自2012 年 1 月,但 0...2... 2来自2011 年 12 月!?)

-bash-4.1$ tree -D pg_xlog/
pg_xlog/
??? [Dec  6  6:27]  000000010000000000000001
??? [Jan 20 21:33]  000000020000000000000001
??? [Dec 21  5:29]  000000020000000000000002
??? [Dec  6  6:30]  00000002.history
??? [Dec  6  6:30]  archive_status
    ??? [Dec  6  6:30]  00000002.history.ready

1 directory, 5 files
-bash-4.1$ cat pg_xlog/00000002.history 
1       000000010000000000000001        no recovery target specified
Run Code Online (Sandbox Code Playgroud)

事务日志:(在master 上

-bash-4.1$ tree -D pg_xlog/
pg_xlog/
??? [Dec  6  6:27]  000000010000000000000001
??? [Jan 21  8:55]  000000020000000000000001
??? [Dec 21  5:31]  000000020000000000000002
??? [Dec  6  6:30]  00000002.history
??? [Dec  6  6:30]  archive_status
    ??? [Dec  6  6:30]  00000002.history.ready

-bash-4.1$ cat pg_xlog/00000002.history 
1       000000010000000000000001        no recovery target specified
Run Code Online (Sandbox Code Playgroud)

配置文件:(在从站上)

---postgresql.conf---
wal_level = hot_standby
...
hot_standby = on
...

---recovery.conf---
standby_mode = 'on'
primary_conninfo = 'host=dw0azewdbpv11danny user=replicator password=...'
recovery_target_timeline = 'latest'
Run Code Online (Sandbox Code Playgroud)

最后,在奴隶上,ps aux表明:

Jan20 0:01 postgres: startup process waiting for 000000020000000000000001

一周后更新

使用 gcc 4.6.0 构建的 PostgreSQL 似乎存在复制错误。
http://archives.postgresql.org/pgsql-general/2011-07/msg00686.php

http://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=45d792f70272ed57b932816562f31c2f79426c2a
不过我你猜那个bug不会影响9.1?

PostgreSQL 版本在 master 和 slave 上应该是相同的,并且 SELECT version() 在 master 和 slave 上看起来像这样:

-bash-4.1$ psql
psql (9.1.1)
Type "help" for help.

postgres=# SELECT version();
                                                   version                                                    
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.1.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.5 20110214 (Red Hat 4.4.5-6), 64-bit
(1 row)
Run Code Online (Sandbox Code Playgroud)

或许还要提一下,现在的主人本来就是奴隶,现在的奴隶本来就是主人。-- 我做了一次故障转移,以测试它是否工作正常。

(我会在 Postgres 邮件列表上问这个问题。)

Chr*_*ers 4

这听起来不像是同一件事。GCC 版本不同,您的 PostgreSQL 版本也不同。IIRC 这是 GCC 4.6 优化的一个问题,现已修复。我认为它不会影响您的设置。

更有可能是某些事情发生了变化,导致了这种情况。也许奴隶短暂地晋升为主人,然后又被降职?这会一直产生这样的问题。

时间线问题向我表明这确实发生了。无论您是否写入数据库,只要完成恢复和升级就足以打破时间线。