From 1348c819f64a6e582d3cc00584ca55db5bc692e2 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Mon, 2 Aug 2021 00:38:53 -0700
Subject: [PATCH v2 2/3] process startup: Do InitProcess() at the same time
 regardless of EXEC_BACKEND.

An upcoming patch splits single user mode into its own function. This makes
that easier. Split out for easier review / testing.

Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20210802164124.ufo5buo4apl6yuvs@alap3.anarazel.de
---
 src/backend/postmaster/postmaster.c |  9 +++++++++
 src/backend/tcop/postgres.c         | 17 +++++------------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index b2fe420c3cf..96e94a55f27 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -4239,6 +4239,15 @@ BackendStartup(Port *port)
 		/* Perform additional initialization and collect startup packet */
 		BackendInitialize(port);
 
+		/*
+		 * Create a per-backend PGPROC struct in shared memory. We must do
+		 * this before we can use LWLocks. In the !EXEC_BACKEND case (here)
+		 * this could be delayed a bit further, but EXEC_BACKEND needs to do
+		 * stuff with LWLocks before PostgresMain(), so we do it here as well
+		 * for symmetry.
+		 */
+		InitProcess();
+
 		/* And run the backend */
 		BackendRun(port);
 	}
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 32d11e53b4d..1dd5800d6b3 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -4057,20 +4057,13 @@ PostgresMain(int argc, char *argv[],
 		 * Remember stand-alone backend startup time
 		 */
 		PgStartTime = GetCurrentTimestamp();
-	}
 
-	/*
-	 * Create a per-backend PGPROC struct in shared memory, except in the
-	 * EXEC_BACKEND case where this was done in SubPostmasterMain. We must do
-	 * this before we can use LWLocks (and in the EXEC_BACKEND case we already
-	 * had to do some stuff with LWLocks).
-	 */
-#ifdef EXEC_BACKEND
-	if (!IsUnderPostmaster)
+		/*
+		 * Create a per-backend PGPROC struct in shared memory. We must do
+		 * this before we can use LWLocks.
+		 */
 		InitProcess();
-#else
-	InitProcess();
-#endif
+	}
 
 	/* Early initialization */
 	BaseInit();
-- 
2.32.0.rc2

