diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-03-18 11:35:08 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-03-18 11:35:30 +0200 |
commit | aafc05de1bf5c0324cb5e690c6742118c1ac4af6 (patch) | |
tree | c750628b17b1175e2ec4bb420275d3b6f2bced6b /src/backend/postmaster/bgworker.c | |
parent | f1baed18bc3db50c72bfb00b6247b47689158445 (diff) | |
download | postgresql-aafc05de1bf5c0324cb5e690c6742118c1ac4af6.tar.gz postgresql-aafc05de1bf5c0324cb5e690c6742118c1ac4af6.zip |
Refactor postmaster child process launching
Introduce new postmaster_child_launch() function that deals with the
differences in EXEC_BACKEND mode.
Refactor the mechanism of passing information from the parent to child
process. Instead of using different command-line arguments when
launching the child process in EXEC_BACKEND mode, pass a
variable-length blob of startup data along with all the global
variables. The contents of that blob depend on the kind of child
process being launched. In !EXEC_BACKEND mode, we use the same blob,
but it's simply inherited from the parent to child process.
Reviewed-by: Tristan Partin, Andres Freund
Discussion: https://www.postgresql.org/message-id/7a59b073-5b5b-151e-7ed3-8b01ff7ce9ef@iki.fi
Diffstat (limited to 'src/backend/postmaster/bgworker.c')
-rw-r--r-- | src/backend/postmaster/bgworker.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index b73e91f0c86..cf64a4beb20 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -720,15 +720,29 @@ bgworker_die(SIGNAL_ARGS) * Main entry point for background worker processes. */ void -BackgroundWorkerMain(void) +BackgroundWorkerMain(char *startup_data, size_t startup_data_len) { sigjmp_buf local_sigjmp_buf; - BackgroundWorker *worker = MyBgworkerEntry; + BackgroundWorker *worker; bgworker_main_type entrypt; - if (worker == NULL) + if (startup_data == NULL) elog(FATAL, "unable to find bgworker entry"); + Assert(startup_data_len == sizeof(BackgroundWorker)); + worker = MemoryContextAlloc(TopMemoryContext, sizeof(BackgroundWorker)); + memcpy(worker, startup_data, sizeof(BackgroundWorker)); + /* + * Now that we're done reading the startup data, release postmaster's + * working memory context. + */ + if (PostmasterContext) + { + MemoryContextDelete(PostmasterContext); + PostmasterContext = NULL; + } + + MyBgworkerEntry = worker; MyBackendType = B_BG_WORKER; init_ps_display(worker->bgw_name); |