Skip to content

Commit dfbba2c

Browse files
committed
Make sure MaxBackends is always set
Auxiliary and bootstrap processes weren't getting it, causing initdb to fail completely.
1 parent cdbc0ca commit dfbba2c

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -899,13 +899,9 @@ PostmasterMain(int argc, char *argv[])
899899

900900
/*
901901
* Now that loadable modules have had their chance to register background
902-
* workers, calculate MaxBackends. Add one for the autovacuum launcher.
902+
* workers, calculate MaxBackends.
903903
*/
904-
MaxBackends = MaxConnections + autovacuum_max_workers + 1 +
905-
GetNumShmemAttachedBgworkers();
906-
/* internal error because the values were all checked previously */
907-
if (MaxBackends > MAX_BACKENDS)
908-
elog(ERROR, "too many backends configured");
904+
InitializeMaxBackends();
909905

910906
/*
911907
* Establish input sockets.

src/backend/utils/init/postinit.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,26 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
421421
}
422422
}
423423

424+
/*
425+
* Initialize MaxBackends value from config options.
426+
*
427+
* This must be called after modules have had the chance to register background
428+
* workers in shared_preload_libraries, and before shared memory size is
429+
* determined.
430+
*/
431+
void
432+
InitializeMaxBackends(void)
433+
{
434+
Assert(MaxBackends == 0);
435+
436+
/* the extra unit accounts for the autovacuum launcher */
437+
MaxBackends = MaxConnections + autovacuum_max_workers + 1 +
438+
GetNumShmemAttachedBgworkers();
439+
440+
/* internal error because the values were all checked previously */
441+
if (MaxBackends > MAX_BACKENDS)
442+
elog(ERROR, "too many backends configured");
443+
}
424444

425445
/*
426446
* Early initialization of a backend (either standalone or under postmaster).
@@ -433,6 +453,8 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
433453
void
434454
BaseInit(void)
435455
{
456+
InitializeMaxBackends();
457+
436458
/*
437459
* Attach to shared memory and semaphores, and initialize our
438460
* input/output/debugging file descriptors.

src/include/miscadmin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ extern AuxProcType MyAuxProcType;
394394

395395
/* in utils/init/postinit.c */
396396
extern void pg_split_opts(char **argv, int *argcp, char *optstr);
397+
extern void InitializeMaxBackends(void);
397398
extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
398399
char *out_dbname);
399400
extern void BaseInit(void);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy