共计 1052 个字符,预计需要花费 3 分钟才能阅读完成。
1、启动恢复时,确定恢复到的时间线 recoveryTargetTLI
1)归档恢复点比 checkpoint 中记录的时间线大,那么选择归档恢复点作为目标时间线
2)否则,checkpoint 记录中的时间线作为目标时间线
StartupXLOG->
if (ControlFile->minRecoveryPointTLI >
ControlFile->checkPointCopy.ThisTimeLineID)
recoveryTargetTLI = ControlFile->minRecoveryPointTLI;
else
recoveryTargetTLI = ControlFile->checkPointCopy.ThisTimeLineID;
…
2、接着从 recovery.conf 文件中读取
1)若设置了 recovery_target_timeline 值,并且设为 latest,那么 history 列表最大的时间线即为目标时间线
2)否则是 recovery.conf 文件中设置的时间线值
3)若没有设置 recovery_target_timeline 值,则目标时间线为第一步中的值
StartupXLOG->readRecoveryCommandFile()->
for (item = head; item; item = item->next){
if (strcmp(item->name, “restore_command”) == 0){
…
}else if …
else if(strcmp(item->name, “recovery_target_timeline”) == 0){
rtliGiven = true;
if (strcmp(item->value, “latest”) == 0)
rtli = 0;
else
rtli = (TimeLineID) strtoul(item->value, NULL, 0);
}else if…
}
if (rtliGiven){
if (rtli){
recoveryTargetTLI = rtli;
recoveryTargetIsLatest = false;
}else{
/* We start the “latest” search from pg_control’s timeline */
recoveryTargetTLI = findNewestTimeLine(recoveryTargetTLI);
recoveryTargetIsLatest = true;
}
}
: