process startup: Do InitProcess() at the same time regardless of EXEC_BACKEND.
authorAndres Freund <andres@anarazel.de>
Thu, 16 Sep 2021 10:23:05 +0000 (03:23 -0700)
committerAndres Freund <andres@anarazel.de>
Thu, 16 Sep 2021 10:23:05 +0000 (03:23 -0700)
An upcoming patch splits single user mode into its own function. This makes
that easier. Split out for easier review / testing.

Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20210802164124.ufo5buo4apl6yuvs@alap3.anarazel.de

src/backend/postmaster/postmaster.c
src/backend/tcop/postgres.c

index d16d881e5704dcdc4f1e435aba507fdf3fbf56a1..2ab7ed7dc395be2182bd7473866b59bce321716c 100644 (file)
@@ -4275,6 +4275,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);
        }
index 489e27f99aef6c511d718c17289b2612ab01bfb1..d85e10d9cef055cacf7d67f68630c39c5574ad1f 100644 (file)
@@ -4058,20 +4058,13 @@ PostgresMain(int argc, char *argv[],
                 * point during startup that postmaster does so.
                 */
                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();