PostgreSQL啓動恢復期間,恢復到的時間線的確定

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;
		}
	}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章