PostgreSQL pg_rewind实例--could not find previous WA 荐

栏目: 数据库 · 发布时间: 6年前

内容简介:一、介绍作为pg_rewind报错章节补充一个用例,说明其用法。二、实例

一、介绍

作为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、查找分叉点

PostgreSQL pg_rewind实例--could not find previous WA 荐

说明: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原理及报错流程分析参考


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Trading and Exchanges

Trading and Exchanges

Larry Harris / Oxford University Press, USA / 2002-10-24 / USD 95.00

This book is about trading, the people who trade securities and contracts, the marketplaces where they trade, and the rules that govern it. Readers will learn about investors, brokers, dealers, arbit......一起来看看 《Trading and Exchanges》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具