From 33d48f51d57b088d2d0f10f9a73e26157f98e0dd Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 8 Sep 2021 10:33:29 -0700
Subject: [PATCH v2 1/3] process startup: Initialize PgStartTime earlier in
 single user mode.

An upcoming patch splits single user mode handling out of PostgresMain(). The
startup time only needs to be determined in single user mode. Currently the
initialization happens late, which makes the split a bit harder. As postmaster
determines the time earlier it makes sense to move the time for single user
mode to a roughly similar point in time.

Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20210802164124.ufo5buo4apl6yuvs@alap3.anarazel.de
---
 src/backend/tcop/postgres.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 58b5960e27d..32d11e53b4d 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -4052,6 +4052,11 @@ PostgresMain(int argc, char *argv[],
 		InitializeMaxBackends();
 
 		CreateSharedMemoryAndSemaphores();
+
+		/*
+		 * Remember stand-alone backend startup time
+		 */
+		PgStartTime = GetCurrentTimestamp();
 	}
 
 	/*
@@ -4161,12 +4166,6 @@ PostgresMain(int argc, char *argv[],
 	initStringInfo(&row_description_buf);
 	MemoryContextSwitchTo(TopMemoryContext);
 
-	/*
-	 * Remember stand-alone backend startup time
-	 */
-	if (!IsUnderPostmaster)
-		PgStartTime = GetCurrentTimestamp();
-
 	/*
 	 * POSTGRES main processing loop begins here
 	 *
-- 
2.32.0.rc2

