diff options
author | Robert Haas <rhaas@postgresql.org> | 2022-04-12 14:45:23 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2022-04-12 14:45:23 -0400 |
commit | 7fc0e7de9fb8306e84d1c15211aba4308f694455 (patch) | |
tree | ce8d0213123959bce52699e8e8d837d46758a2f6 /src/backend/utils/init/postinit.c | |
parent | 2c9381840fe2d6d1c3179350493fe5fd3dcf90b5 (diff) | |
download | postgresql-7fc0e7de9fb8306e84d1c15211aba4308f694455.tar.gz postgresql-7fc0e7de9fb8306e84d1c15211aba4308f694455.zip |
Revert the addition of GetMaxBackends() and related stuff.
This reverts commits 0147fc7, 4567596, aa64f23, and 5ecd018.
There is no longer agreement that introducing this function
was the right way to address the problem. The consensus now
seems to favor trying to make a correct value for MaxBackends
available to mdules executing their _PG_init() functions.
Nathan Bossart
Discussion: http://postgr.es/m/20220323045229.i23skfscdbvrsuxa@jrouhaud
Diffstat (limited to 'src/backend/utils/init/postinit.c')
-rw-r--r-- | src/backend/utils/init/postinit.c | 55 |
1 files changed, 9 insertions, 46 deletions
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index a85c2e0260d..9139fe895c0 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -25,7 +25,6 @@ #include "access/session.h" #include "access/sysattr.h" #include "access/tableam.h" -#include "access/twophase.h" #include "access/xact.h" #include "access/xlog.h" #include "access/xloginsert.h" @@ -68,9 +67,6 @@ #include "utils/syscache.h" #include "utils/timeout.h" -static int MaxBackends = 0; -static int MaxBackendsInitialized = false; - static HeapTuple GetDatabaseTuple(const char *dbname); static HeapTuple GetDatabaseTupleByOid(Oid dboid); static void PerformAuthentication(Port *port); @@ -542,8 +538,9 @@ 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 alter GUCs in - * shared_preload_libraries and before shared memory size is determined. + * 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. * * Note that in EXEC_BACKEND environment, the value is passed down from * postmaster to subprocesses via BackendParameters in SubPostmasterMain; only @@ -553,49 +550,15 @@ pg_split_opts(char **argv, int *argcp, const char *optstr) void InitializeMaxBackends(void) { - /* the extra unit accounts for the autovacuum launcher */ - SetMaxBackends(MaxConnections + autovacuum_max_workers + 1 + - max_worker_processes + max_wal_senders); -} + Assert(MaxBackends == 0); -/* - * Safely retrieve the value of MaxBackends. - * - * Previously, MaxBackends was externally visible, but it was often used before - * it was initialized (e.g., in preloaded libraries' _PG_init() functions). - * Unfortunately, we cannot initialize MaxBackends before processing - * shared_preload_libraries because the libraries sometimes alter GUCs that are - * used to calculate its value. Instead, we provide this function for accessing - * MaxBackends, and we ERROR if someone calls it before it is initialized. - */ -int -GetMaxBackends(void) -{ - if (unlikely(!MaxBackendsInitialized)) - elog(ERROR, "MaxBackends not yet initialized"); - - return MaxBackends; -} - -/* - * Set the value of MaxBackends. - * - * This should only be used by InitializeMaxBackends() and - * restore_backend_variables(). If MaxBackends is already initialized or the - * specified value is greater than the maximum, this will ERROR. - */ -void -SetMaxBackends(int max_backends) -{ - if (MaxBackendsInitialized) - elog(ERROR, "MaxBackends already initialized"); + /* the extra unit accounts for the autovacuum launcher */ + MaxBackends = MaxConnections + autovacuum_max_workers + 1 + + max_worker_processes + max_wal_senders; /* internal error because the values were all checked previously */ - if (max_backends > MAX_BACKENDS) + if (MaxBackends > MAX_BACKENDS) elog(ERROR, "too many backends configured"); - - MaxBackends = max_backends; - MaxBackendsInitialized = true; } /* @@ -707,7 +670,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, SharedInvalBackendInit(false); - if (MyBackendId > GetMaxBackends() || MyBackendId <= 0) + if (MyBackendId > MaxBackends || MyBackendId <= 0) elog(FATAL, "bad backend ID: %d", MyBackendId); /* Now that we have a BackendId, we can participate in ProcSignal */ |