Advance TimeLineID after standby promoted, which follows upstream.
A timeline history file would be generated to track timeline change,
and we copy the last wal file as wal file of current timeline. The split
point in history file would take care of correct recovery.
Author: Xiaoran Wang
Author: Max Yang
@@ -7462,6 +7462,19 @@ StartupXLOG(void)
writeTimeLineHistory(ThisTimeLineID, recoveryTargetTLI,
curFileTLI, endLogId, endLogSeg);
}
+ else if (ControlFile->state == DB_IN_STANDBY_PROMOTED)
+ {
+ /*
+ * If standby is promoted, we should advance timeline ID.
+ */
+ ThisTimeLineID = findNewestTimeLine(recoveryTargetTLI) + 1;
+ ereport(LOG,
+ (errmsg("selected new timeline ID: %u", ThisTimeLineID)));
+ writeTimeLineHistory(ThisTimeLineID, recoveryTargetTLI,
+ curFileTLI, endLogId, endLogSeg);
+
+ XLogFileCopy(endLogId, endLogSeg, curFileTLI, endLogId, endLogSeg);
+ }
/* Save the selected TimeLineID in shared memory, too */
XLogCtl->ThisTimeLineID = ThisTimeLineID;
