1. 程式人生 > >PostgreSQL啟動恢復期間,恢復到的時間線的確定

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

否則 == targe bar -s recover postgresq 文件 true

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


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