aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2013-01-02 14:39:11 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2013-01-02 14:39:11 -0300
commitdfbba2c86cc8f09cf3ffca3d305b4ce54a7fb49a (patch)
tree55c6fcee0599a5a1fadbca91c2b448f326b3895d
parentcdbc0ca48ca96e5c787b1605ed2d6cf7407a5acf (diff)
downloadpostgresql-dfbba2c86cc8f09cf3ffca3d305b4ce54a7fb49a.tar.gz
postgresql-dfbba2c86cc8f09cf3ffca3d305b4ce54a7fb49a.zip
Make sure MaxBackends is always set
Auxiliary and bootstrap processes weren't getting it, causing initdb to fail completely.
-rw-r--r--src/backend/postmaster/postmaster.c8
-rw-r--r--src/backend/utils/init/postinit.c22
-rw-r--r--src/include/miscadmin.h1
3 files changed, 25 insertions, 6 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index fa5aeed31db..15c23204611 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -899,13 +899,9 @@ PostmasterMain(int argc, char *argv[])
/*
* Now that loadable modules have had their chance to register background
- * workers, calculate MaxBackends. Add one for the autovacuum launcher.
+ * workers, calculate MaxBackends.
*/
- MaxBackends = MaxConnections + autovacuum_max_workers + 1 +
- GetNumShmemAttachedBgworkers();
- /* internal error because the values were all checked previously */
- if (MaxBackends > MAX_BACKENDS)
- elog(ERROR, "too many backends configured");
+ InitializeMaxBackends();
/*
* Establish input sockets.
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 0fbf65f7340..3948eac039b 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -421,6 +421,26 @@ pg_split_opts(char **argv, int *argcp, 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.
+ */
+void
+InitializeMaxBackends(void)
+{
+ Assert(MaxBackends == 0);
+
+ /* the extra unit accounts for the autovacuum launcher */
+ MaxBackends = MaxConnections + autovacuum_max_workers + 1 +
+ GetNumShmemAttachedBgworkers();
+
+ /* internal error because the values were all checked previously */
+ if (MaxBackends > MAX_BACKENDS)
+ elog(ERROR, "too many backends configured");
+}
/*
* Early initialization of a backend (either standalone or under postmaster).
@@ -433,6 +453,8 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
void
BaseInit(void)
{
+ InitializeMaxBackends();
+
/*
* Attach to shared memory and semaphores, and initialize our
* input/output/debugging file descriptors.
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 2fb7be48adf..99858a765f1 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -394,6 +394,7 @@ extern AuxProcType MyAuxProcType;
/* in utils/init/postinit.c */
extern void pg_split_opts(char **argv, int *argcp, char *optstr);
+extern void InitializeMaxBackends(void);
extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
char *out_dbname);
extern void BaseInit(void);