From cb14fe3a02fe3db03e46d0371ac6cc8a2b113576 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Mon, 25 Jan 2021 11:04:22 -0500
Subject: [PATCH v1 1/4] Move StartupCLOG() calls to just after we initialize
 ShmemVariableCache.

Previously, the hot_standby=off code path did this at end of recovery,
while the hot_standby=on code path did it at the beginning of recovery.
It's better to do this in only one place because (a) it's simpler,
(b) StartupCLOG() is trivial so trying to postpone the work isn't
useful, and (c) this will make it possible to simplify some other
logic.
---
 src/backend/access/transam/xlog.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 470e113b33..1cfee5c270 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6859,6 +6859,13 @@ StartupXLOG(void)
 	 */
 	StartupReorderBuffer();
 
+	/*
+	 * Startup CLOG. This must be done after ShmemVariableCache->nextXid
+	 * has been initialized and before we accept connections or begin WAL
+	 * replay.
+	 */
+	StartupCLOG();
+
 	/*
 	 * Startup MultiXact. We need to do this early to be able to replay
 	 * truncations.
@@ -7129,11 +7136,10 @@ StartupXLOG(void)
 			ProcArrayInitRecovery(XidFromFullTransactionId(ShmemVariableCache->nextXid));
 
 			/*
-			 * Startup commit log and subtrans only.  MultiXact and commit
+			 * Startup subtrans only.  CLOG, MultiXact and commit
 			 * timestamp have already been started up and other SLRUs are not
 			 * maintained during recovery and need not be started yet.
 			 */
-			StartupCLOG();
 			StartupSUBTRANS(oldestActiveXID);
 
 			/*
@@ -7949,14 +7955,11 @@ StartupXLOG(void)
 	LWLockRelease(ProcArrayLock);
 
 	/*
-	 * Start up the commit log and subtrans, if not already done for hot
-	 * standby.  (commit timestamps are started below, if necessary.)
+	 * Start up subtrans, if not already done for hot standby.  (commit
+	 * timestamps are started below, if necessary.)
 	 */
 	if (standbyState == STANDBY_DISABLED)
-	{
-		StartupCLOG();
 		StartupSUBTRANS(oldestActiveXID);
-	}
 
 	/*
 	 * Perform end of recovery actions for any SLRUs that need it.
-- 
2.24.3 (Apple Git-128)

