PostgreSQL standby replication error : invalid record length at %u

一位QQ上的网友问我的一个问题,我觉得比较有意思。

记录如下 : 

Question : 

我在启动POSTGRES的STANDBY数据库时,报

--------------------------

LOG:  database system was shut down in recovery at 2011-12-30 23:20:25 CST

LOG:  entering standby mode

LOG:  restored log file "0000000100000002000000E9" from archive

LOG:  invalid record length at 2/E9000108

LOG:  invalid record length at 2/E9000108

LOG:  streaming replication successfully connected to primary

LOG:  invalid record length at 2/E9000108

FATAL:  terminating walreceiver process due to administrator command

LOG:  restored log file "0000000100000002000000E9" from archive

LOG:  invalid record length at 2/E9000108

FATAL:  the database system is starting up

LOG:  invalid record length at 2/E9000108

LOG:  restored log file "0000000100000002000000E9" from archive

LOG:  invalid record length at 2/E9000108

--------------------------------------

我是把主库整个做了个TAR 包到备库的

问题分析 : 

报错invalid record length at 2/E9000108

源码中对应的部分如下 : 

        /*

         * NOTE: We disallow len == 0 because it provides a useful bit of extra

         * error checking in ReadRecord.  This means that all callers of

         * XLogInsert must supply at least some not-in-a-buffer data.  However, we

         * make an exception for XLOG SWITCH records because we don't want them to

         * ever cross a segment boundary.

         */

        if (len == 0 && !isLogSwitch)

                elog(PANIC, "invalid xlog record length %u", len);

        START_CRIT_SECTION();

因此报错的原因是standby在恢复过程中从 xlog 0000000100000002000000E9 的 2/E9000108位置读取到了len == 0 并且 !isLogSwitch 的信息。

日志中还提到了restored log file "0000000100000002000000E9" from archive

因此问他要了recovery.conf 配置文件的内容如下 : 

standby_mode = 'on'
primary_conninfo = 'host=隐藏 port=5432 user=隐藏 password=隐藏'
restore_command = 'cp "/home/postgres/data/pg_xlog/%f" "%p"'
trigger_file = '/home/postgres/trigger_activestb'

从这个配置文件来看,restore_command = 'cp "/home/postgres/data/pg_xlog/%f" "%p"' 有问题,如果要配置restore_command,那么应该是把主库的归档文件拷贝standby的pg_xlog目录。

要么就是不要配置restore_command , 那么standby会尝试从stream获取xlog的信息(要求primary库的这个xlog没有被覆盖)。

Answer : 

经过确认主库的 0000000100000002000000E9 存在pg_xlog中未被覆盖.

注释standby节点recovery.conf的restore_command = 'cp "/home/postgres/data/pg_xlog/%f" "%p"'

重启standby.

未解决,还是报 invalid record length at 2/E9000108 

另外需要了解的是,

  做STANDBY的时候有没有按照正常流程来做( select pg_start_backup(), backup, select pg_stop_backup() )

  拷贝数据文件的过程中有没有错误发生.

  这些都不得而知, 因此问题不太好判断。

  所以先重做 standby 来解决目前的问题 . 

最后.

可以尝试使用pg_filedump来分析一下 0000000100000002000000E9的内容。(由于时间关系,暂时没做)

 

【参考】

src/backend/access/transam/xlog.c

http://blog.163.com/digoal@126/blog/static/163877040201142610215685/

时间: 2024-08-03 15:32:20

PostgreSQL standby replication error : invalid record length at %u的相关文章

ERROR: invalid page header in block 27073 of relation base/21078/45300926

突然断网,检查后通知我们UPS断电,db所在主机重启 1.连上后,发现pg主从不同步,主不向从传日志,从报错: FATAL: could not connect to the primary server: could not connect to server: 发现从先启动成功,而主是后启动的,因此我们将从再次重启 service postgresql restart 开始正常传日志  2.过了一会,研发反应部分表的使用出现问题,主再次不传输日志,且无sender进程. 查看主库日志,发现报

PostgreSQL Streaming Replication COMMAND used in psql

CF里面在讨论是否要添加一个查看数据库system id的函数, pg_system_identifier(); http://www.postgresql.org/message-id/flat/5215346B.7070800@dalibo.com#5215346B.7070800@dalibo.com 这个函数的用途和pg_controldata输出的Database system identifier值其实是一个效果. 只是它的目的是可以用SQL来得到这个值. 看到后面发现一个很有趣的东

[rsync][cwRsync]@ERROR: invalid uid administrator错误

如题所描述的错误,在客户端执行 rsync同步的时候同样会提示一个没见到过的错误,但是根据报错信息和互联网搜索,可以得到大致是解决的方案,我汇总一下,如下所展示,如果您遇到了类似的问题,希望能够这样解决: 1.首先去服务器端的cwRsync上面检查安装目录下是否有 rsyncd.conf 这个文件,这个文件是进行配置reync服务端的配置文件,里面的默认内容为: use chroot = false strict modes = false hosts allow = * log file =

mips-简单的MIPS汇编,error:invalid program counter value:0

问题描述 简单的MIPS汇编,error:invalid program counter value:0 .data 0x10000000 .text main: addu $s7,$ra,$0 li $v0,5 syscall addi $a0,$v0,0 j fact li $v0,1 syscall addu $ra,$0,$s7 jr $ra fact: addi $sp,$sp,-8 sw $ra,4($sp) sw $a0,0($sp) slti $t0,$a0,1 beq $t0,

win 7 centos 安装-装了centos7. windows7引导没了。上网查了,改了配置文件,点windows7结果出来error:invalid signature

问题描述 装了centos7. windows7引导没了.上网查了,改了配置文件,点windows7结果出来error:invalid signature 救援模式下.grub> ls 输出(hd0) (hd0msdos2) (hd0msdos1) 解决方案 有几个可能,一个是你的windows 7是盗版的,盗版win7的工作原理是在启动前加载一个bios驱动,骗过windows认为是oem品牌机,达到激活的目的,但是很不幸,这个加载程序和grub引导不兼容.解决办法是换用基于kms/mak方式

android-Fatal error: invalid -march= option: `armv5te'

问题描述 Fatal error: invalid -march= option: `armv5te' android2-2编译时出错-找不出是什么原因,求解? Fatal error: invalid -march= option: `armv5te' 解决方案 试一下Error while compiling android jni sample: invalid -march= option: `armv5te' 添加一个文件链接 $ ln -s $NDK_PATH/toolchains/

smarty smarty syntax error: invalid attribute name

smarty smarty syntax error: invalid attribute name Smarty error: [in file:xx.tpl line 1]: syntax error: invalid attribute name: 'index.tpl' (Smarty_Compiler.class.php, line 1521) //当你遇到这个错误时,说明你的magic_quotes_runtime设置是打开的在你的php.ini配置文件. //smarty需要在这个

nginx安装报错:nginx: [error] invalid PID number

搞了一个美国服务器,重新弄了下nginx安装配置,重新/usr/local/nginx/sbin/nginx -s reload 提示如下报错: [root@Kvmla-201606291067 conf]# /usr/local/nginx/sbin/nginx   -s reload nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid" 无效的pid号. 网上搜索资料解

[org.apache.struts.action.RequestProcessor]-[ERROR] Invalid path was requested

问题描述 路径问题: [org.apache.struts.action.RequestProcessor]-[ERROR] Invalid path was requested /form/logininjsp页面内容<form method="post" action="loginin.do" returnlogin_email()>email :<input name="email" type="text&quo