pg_rewind实例--could not find previous WAL record at %X/%X

简介: pg_rewind实例--could not find previous WAL record at %X/%X

一、介绍


   作为pg_rewind报错章节补充一个用例,说明其用法。


二、实例


   1、history文件

--新主
$ cat 00000004.history
1    0/140000C8    no recovery target specified
2    0/19000060    no recovery target specified
3    0/1F000090    no recovery target specified
--老主
$ cat 00000003.history
1    0/140000C8    no recovery target specified
2    0/19000060    no recovery target specified

2、查找分叉点


说明:findCommonAncestorTimeline:

 1)比较sourceHistory[0]、targetHistory[0]的时间线和begin的值,可以得出两者相等,则转到第2个条目的比较

 2)比较sourceHistory[1]、targetHistory[1]的时间线和begin的值,可以得出两者相等,则转到第3个条目的比较

 3)比较sourceHistory[2]、targetHistory[2]的时间线和begin的值,可以得出两者相等,此时比较结束

 4)取第3个条目进行返回:MinXLogRecPtr(sourceHistory[i].end, targetHistory[i].end),此时返回的是sourceHistory[i].end的值作为分叉点,即 0/1F000090

3、此时ControlFile_target.checkPoint < divergerec && target的chkptendrec!=divergerec,所以可以进行pg_rewind

4、findLastCheckpoint查找分叉点divergerec之前最近的checkpoint作为rewind起点。

 1)首先需要定位到分叉点divergerec开始的记录,然后根据该记录的xl_prev指针定位前一个wal记录

 2)判断第1)步得到的wal记录是否是checkpoint,如果不是则重新返回到第1),直到找到checkpoint点

 3)这里就有个问题,如果得到的分叉点正好是老主结束位置,即本例:1F000090为分叉点,实际上是老主和新主没有发生数据分叉,可以认为是没有作为备没有接收完新主数据呢

 4)target从1F000090这个位置开始获取prev指针向前找checkpoint时,因为这个位置后都是0了,所以不能继续向下遍历找了,报错:could not find previous WAL record at %X/%X


三、小结


   这里pg_rewind执行时,判断不出来没有分叉的情景,即本文的场景。此时执行pg_rewind会报错,让用户还以为WAL文件由损坏导致执行pg_rewind失败。这个工具如果能够将这种场景识别出来,报不需要rewind是不是更好?


四、pg_rewind原理及报错流程分析参考


   http://blog.itpub.net/31493717/viewspace-2639207/

   http://blog.itpub.net/31493717/viewspace-2286140/

目录
相关文章
|
10月前
|
存储 SQL 缓存
【MySQL】change buffer,buffer pool,redo log,bin log,undo log的作用
【MySQL】change buffer,buffer pool,redo log,bin log,undo log的作用
94 0
|
12月前
|
Oracle 前端开发 关系型数据库
log file sync 和 log file parallel write等待事件的区别和联系
log file parallel write 和log file sync这两个等待事件关系密切,很多人对这两个等待事件有一些误解,我们先来看看Oracle官方文档的解释:
|
关系型数据库 数据库 PostgreSQL
PG异常无法启动的问题:could not read file "pg_logical/replorigin_checkpoint": Success
问题描述 新安装不久的PostgreSQL数据库,断电后重启,查看日志如下 2019-01-08 08:44:19.989 UTC [7493] LOG: database system was interrupted; last known up at 2018-12-24 10:56:28 UTC 2019-01-08 08:44:19.
3237 0
why my CREATE_OW will not generate OSSET entry in OB buffer
why my CREATE_OW will not generate OSSET entry in OB buffer
95 0
why my CREATE_OW will not generate OSSET entry in OB buffer
|
测试技术
[20171123]Skip Locked and ITL slot 2.txt
[20171123]Skip Locked and ITL slot 2.txt --//昨天看链接提到Skip Locked and ITL slot相关问题,链接 http://jonathanlewis.
1072 0
|
数据库管理 关系型数据库 Oracle
|
关系型数据库