aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/init/postinit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/init/postinit.c')
-rw-r--r--src/backend/utils/init/postinit.c55
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 */