public inbox for [email protected]
help / color / mirror / Atom feedFrom: Wang, Shenhao <[email protected]>
To: [email protected] <[email protected]>
Subject: make MaxBackends available in _PG_init
Date: Mon, 21 Sep 2020 03:43:41 +0000
Message-ID: <4f20d57b2aeb447b8eb1495319940c5f@G08CNEXMBPEKD06.g08.fujitsu.local> (raw)
Hi Hackers:
I find the value in function _PG_init, the value of MaxBackends is 0.
In source, I find that the postmaster will first load library, and then calculate the value of MaxBackends.
In the old version, the MaxBackends was calculated by:
MaxBackends = MaxConnections + autovacuum_max_workers + 1 +
GetNumShmemAttachedBgworkers();
Because any extension can register workers which will affect the return value of GetNumShmemAttachedBgworkers.
InitializeMaxBackends must be called after shared_preload_libraries. This is also mentioned in comments.
Now, function GetNumShmemAttachedBgworkers was deleted and replaced by guc max_worker_processes,
so if we changed the calling order like:
Step1: calling InitializeMaxBackends.
Step2: calling process_shared_preload_libraries
In this order extension can get the correct value of MaxBackends in _PG_init.
Any thoughts?
Regards
Attachments:
[application/octet-stream] 0001-Make-MaxBackends-available-in-_PG_init.patch (2.2K, ../4f20d57b2aeb447b8eb1495319940c5f@G08CNEXMBPEKD06.g08.fujitsu.local/2-0001-Make-MaxBackends-available-in-_PG_init.patch)
download | inline diff:
From 1bc1f06337bfffc57d4ac25147a7b981ef89bcbf Mon Sep 17 00:00:00 2001
From: Shenhao Wang <[email protected]>
Date: Fri, 18 Sep 2020 18:35:54 +0800
Subject: [PATCH] Make MaxBackends available in _PG_init
---
src/backend/postmaster/postmaster.c | 17 +++++++----------
src/backend/utils/init/postinit.c | 4 +---
2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 959e3b8873..8da50cb2a1 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -989,13 +989,16 @@ PostmasterMain(int argc, char *argv[])
LocalProcessControlFile(false);
/*
- * Register the apply launcher. Since it registers a background worker,
- * it needs to be called before InitializeMaxBackends(), and it's probably
- * a good idea to call it before any modules had chance to take the
- * background worker slots.
+ * Register the apply launcher. It's probably a good idea to call it
+ * before any modules had chance to take the background worker slots.
*/
ApplyLauncherRegister();
+ /*
+ * Calculate MaxBackends.
+ */
+ InitializeMaxBackends();
+
/*
* process any libraries that should be preloaded at postmaster start
*/
@@ -1012,12 +1015,6 @@ PostmasterMain(int argc, char *argv[])
}
#endif
- /*
- * Now that loadable modules have had their chance to register background
- * workers, calculate MaxBackends.
- */
- InitializeMaxBackends();
-
/*
* Set up shared memory and semaphores.
*/
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index d4ab4c7e23..06d813f76b 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -513,9 +513,7 @@ pg_split_opts(char **argv, int *argcp, const char *optstr)
/*
* Initialize MaxBackends value from config options.
*
- * This must be called after modules have had the chance to register background
- * workers in shared_preload_libraries, and before shared memory size is
- * determined.
+ * This must be called before shared memory size is determined.
*
* Note that in EXEC_BACKEND environment, the value is passed down from
* postmaster to subprocesses via BackendParameters in SubPostmasterMain; only
--
2.21.0
view thread (67+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: make MaxBackends available in _PG_init
In-Reply-To: <4f20d57b2aeb447b8eb1495319940c5f@G08CNEXMBPEKD06.g08.fujitsu.local>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox