PostgreSQL構建流復制拉取日誌的起始位置在哪裏
阿新 • • 發佈:2018-11-04
並且 etl for ptr log led timeline ive ont
WaitForWALToBecomeAvailable:
if (!InArchiveRecovery)
currentSource = XLOG_FROM_PG_WAL;
else if (currentSource == 0)
currentSource = XLOG_FROM_ARCHIVE;
for (;;){
int oldSource = currentSource;
if (lastSourceFailed){
switch (currentSource){
case XLOG_FROM_ARCHIVE:
case XLOG_FROM_PG_WAL://如果是備機,並且執行了promote或者存在TriggerFile文件則shutdown receive進程
if (StandbyMode && CheckForStandbyTrigger()){
ShutdownWalRcv();
return false;
}
if (!StandbyMode)
return false;
/*
構建流復制關系的位點:
1、如果上次正常關閉,不需要恢復,則從checkpoint點開始
2、否則,從恢復的結束位置開始
*/
if (PrimaryConnInfo){
if (fetching_ckpt){
ptr = RedoStartLSN;
tli = ControlFile->checkPointCopy.ThisTimeLineID;
}else{
ptr = RecPtr;
tli = tliOfPointInHistory(tliRecPtr, expectedTLEs);
}
curFileTLI = tli;
RequestXLogStreaming(tli, ptr, PrimaryConnInfo, PrimarySlotName);
receivedUpto = 0;
}
currentSource = XLOG_FROM_STREAM;
break;
...
}
}
...
}
/*
1、流復制拉取日誌的起始位置是位點所在文件的文件開頭
2、也就是說,會以重新拉取整個xlog的文件並覆蓋pg_xlog目錄的相應文件
3、所以,當以主shutdown,再次以備啟動時,需要註意,會從新主拉取相應文件並
4、覆蓋本地文件,但是本地的pg_control文件並沒有更新,所以讀取的checkpoint位置會指向一個錯誤的位置
5、這種情況構建流復制需要謹慎註意。
*/
RequestXLogStreaming:
if (recptr % XLogSegSize != 0)
recptr -= recptr % XLogSegSize;
walrcv->receiveStart = recptr;
walrcv->receiveStartTLI = tli;
SendPostmasterSignal(PMSIGNAL_START_WALRECEIVER);//發起信號喚醒receiver進程
PostgreSQL構建流復制拉取日誌的起始位置在哪裏