PostgreSQL standby replication error : invalid record length at %u

本文涉及的产品
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
简介:
一位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
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
关系型数据库 PostgreSQL
PostgreSQL 计算字符串字符数函数(CHAR_LENGTH(str))和字符串长度函数(LENGTH(str))
PostgreSQL 计算字符串字符数函数(CHAR_LENGTH(str))和字符串长度函数(LENGTH(str))
1792 0
|
2月前
|
分布式计算 DataWorks 关系型数据库
DataWorks操作报错合集之使用连接串模式新增PostgreSQL数据源时遇到了报错"not support data sync channel, error code: 0001",该怎么办
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
|
4月前
|
人工智能 关系型数据库 数据库
PostgreSQL 常见问题解决方案 - ERROR: database is being accessed by other users
PostgreSQL 常见问题解决方案 - ERROR: database is being accessed by other users
|
数据可视化 关系型数据库 数据库
Windows安装PostgreSQL失败:There has been an error
Windows安装PostgreSQL失败:There has been an error
591 0
|
关系型数据库 数据库 PostgreSQL
postgresql :ERROR: role “user001“ cannot be dropped because some objects depend on it
postgresql :ERROR: role “user001“ cannot be dropped because some objects depend on it
848 0
|
关系型数据库 PostgreSQL
PostgreSQL - ERROR: could not determine data type of parameter $1
PostgreSQL - ERROR: could not determine data type of parameter $1
1764 0
|
SQL 关系型数据库 PostgreSQL
postgresql:org.postgresql.util.PSQLException: ERROR: syntax error at or near “$8“
postgresql:org.postgresql.util.PSQLException: ERROR: syntax error at or near “$8“
546 0
postgresql:org.postgresql.util.PSQLException: ERROR: syntax error at or near “$8“
|
关系型数据库 数据库 数据安全/隐私保护