summaryrefslogtreecommitdiff
path: root/src/backend/postmaster
diff options
context:
space:
mode:
authorAndres Freund2021-08-05 21:37:09 +0000
committerAndres Freund2021-08-05 22:36:59 +0000
commitb406478b87e2234c0be4ca4105eee3bb466a646b (patch)
treeafe7c717314d513a9c372604d010b53a601763d4 /src/backend/postmaster
parent0de13bbc47d19c95de132cc85c341fdab079c170 (diff)
process startup: Always call Init[Auxiliary]Process() before BaseInit().
For EXEC_BACKEND InitProcess()/InitAuxiliaryProcess() needs to have been called well before we call BaseInit(), as SubPostmasterMain() needs LWLocks to work. Having the order of initialization differ between platforms makes it unnecessarily hard to understand the system and to add initialization points for new subsystems without a lot of duplication. To be able to change the order, BaseInit() cannot trigger CreateSharedMemoryAndSemaphores() anymore - obviously that needs to have happened before we can call InitProcess(). It seems cleaner to create shared memory explicitly in single user/bootstrap mode anyway. After this change the separation of bufmgr initialization into InitBufferPoolAccess() / InitBufferPoolBackend() is not meaningful anymore so the latter is removed. Author: Andres Freund <andres@anarazel.de> Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/20210802164124.ufo5buo4apl6yuvs@alap3.anarazel.de
Diffstat (limited to 'src/backend/postmaster')
-rw-r--r--src/backend/postmaster/autovacuum.c12
-rw-r--r--src/backend/postmaster/auxprocess.c7
-rw-r--r--src/backend/postmaster/bgworker.c16
3 files changed, 16 insertions, 19 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 912ef9cb54c..59d348b062f 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -469,9 +469,6 @@ AutoVacLauncherMain(int argc, char *argv[])
pqsignal(SIGFPE, FloatExceptionHandler);
pqsignal(SIGCHLD, SIG_DFL);
- /* Early initialization */
- BaseInit();
-
/*
* Create a per-backend PGPROC struct in shared memory, except in the
* EXEC_BACKEND case where this was done in SubPostmasterMain. We must do
@@ -482,6 +479,9 @@ AutoVacLauncherMain(int argc, char *argv[])
InitProcess();
#endif
+ /* Early initialization */
+ BaseInit();
+
InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false);
SetProcessingMode(NormalProcessing);
@@ -1547,9 +1547,6 @@ AutoVacWorkerMain(int argc, char *argv[])
pqsignal(SIGFPE, FloatExceptionHandler);
pqsignal(SIGCHLD, SIG_DFL);
- /* Early initialization */
- BaseInit();
-
/*
* Create a per-backend PGPROC struct in shared memory, except in the
* EXEC_BACKEND case where this was done in SubPostmasterMain. We must do
@@ -1560,6 +1557,9 @@ AutoVacWorkerMain(int argc, char *argv[])
InitProcess();
#endif
+ /* Early initialization */
+ BaseInit();
+
/*
* If an exception is encountered, processing resumes here.
*
diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c
index 196ee647cfe..16d87e91402 100644
--- a/src/backend/postmaster/auxprocess.c
+++ b/src/backend/postmaster/auxprocess.c
@@ -90,8 +90,6 @@ AuxiliaryProcessMain(AuxProcType auxtype)
SetProcessingMode(BootstrapProcessing);
IgnoreSystemIndexes = true;
- BaseInit();
-
/*
* As an auxiliary process, we aren't going to do the full InitPostgres
* pushups, but there are a couple of things that need to get lit up even
@@ -106,6 +104,8 @@ AuxiliaryProcessMain(AuxProcType auxtype)
InitAuxiliaryProcess();
#endif
+ BaseInit();
+
/*
* Assign the ProcSignalSlot for an auxiliary process. Since it doesn't
* have a BackendId, the slot is statically allocated based on the
@@ -118,9 +118,6 @@ AuxiliaryProcessMain(AuxProcType auxtype)
*/
ProcSignalInit(MaxBackends + MyAuxProcType + 1);
- /* finish setting up bufmgr.c */
- InitBufferPoolBackend();
-
/*
* Auxiliary processes don't run transactions, but they may need a
* resource owner anyway to manage buffer pins acquired outside
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index c40410d73ea..11c4ceddbf6 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -838,14 +838,6 @@ StartBackgroundWorker(void)
if (worker->bgw_flags & BGWORKER_SHMEM_ACCESS)
{
/*
- * Early initialization. Some of this could be useful even for
- * background workers that aren't using shared memory, but they can
- * call the individual startup routines for those subsystems if
- * needed.
- */
- BaseInit();
-
- /*
* 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
@@ -854,6 +846,14 @@ StartBackgroundWorker(void)
#ifndef EXEC_BACKEND
InitProcess();
#endif
+
+ /*
+ * Early initialization. Some of this could be useful even for
+ * background workers that aren't using shared memory, but they can
+ * call the individual startup routines for those subsystems if
+ * needed.
+ */
+ BaseInit();
}
/*