From 680272add19e8856503da78437ec5080c99b6fb7 Mon Sep 17 00:00:00 2001
From: Dilip Kumar <dilipkumar@localhost.localdomain>
Date: Tue, 4 May 2021 17:04:45 +0530
Subject: [PATCH] After reading checkpoint record fix expectedTLEs to point to
 recoveryTargetTLI

As part of the commit ee994272ca50f70b53074f0febaec97e28f83c4e, we have detalayed
reading the timeline history file but recoveryTargetTLI is pointing to the target
timeline.  And once it read the checkpoint record it initialize the expectedTLEs
based on the checkpoint record timeline history which change the meaning of the
expectedTLEs which says that it should always point to the recoveryTargetTLI.
So this patch fixes this by re initializing the expectedTLEs based on the
recoveryTargetTLI, after reading the checkpoint record.
---
 src/backend/access/transam/xlog.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index adfc6f6..952d2b7 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6880,6 +6880,13 @@ StartupXLOG(void)
 
 	LastRec = RecPtr = checkPointLoc;
 
+	/*
+	 * Release the current expectedTLEs which is used for reading the
+	 * checkpoint record.  And, reinitialize based on the recoveryTargetTLI.
+	 */
+	list_free_deep(expectedTLEs);
+	expectedTLEs = readTimeLineHistory(recoveryTargetTLI);
+
 	ereport(DEBUG1,
 			(errmsg_internal("redo record is at %X/%X; shutdown %s",
 							 LSN_FORMAT_ARGS(checkPoint.redo),
-- 
1.8.3.1

