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

This is useful because it makes it easier to extract the setup for single user
mode into its own function.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/backend/postmaster/postmaster.c |  9 +++++++++
 src/backend/tcop/postgres.c         | 13 +------------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 65bc4dcbbd6..acecb4a5c9d 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -4224,6 +4224,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 58b5960e27d..6e22e2634b5 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -4052,20 +4052,9 @@ PostgresMain(int argc, char *argv[],
 		InitializeMaxBackends();
 
 		CreateSharedMemoryAndSemaphores();
-	}
 
-	/*
-	 * 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)
 		InitProcess();
-#else
-	InitProcess();
-#endif
+	}
 
 	/* Early initialization */
 	BaseInit();
-- 
2.32.0.rc2

