mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Revert the addition of GetMaxBackends() and related stuff.
This reverts commits0147fc7
,4567596
,aa64f23
, and5ecd018
. 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
This commit is contained in:
@ -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)
|
||||
{
|
||||
Assert(MaxBackends == 0);
|
||||
|
||||
/* the extra unit accounts for the autovacuum launcher */
|
||||
SetMaxBackends(MaxConnections + autovacuum_max_workers + 1 +
|
||||
max_worker_processes + max_wal_senders);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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");
|
||||
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 */
|
||||
|
Reference in New Issue
Block a user