diff options
author | Robert Haas <rhaas@postgresql.org> | 2013-07-04 11:24:24 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2013-07-04 11:24:24 -0400 |
commit | 6bc8ef0b7f1f1df3998745a66e1790e27424aa0c (patch) | |
tree | 69fc9655772dc63e07c96e0c0e4777af7d2068b6 /src/backend/postmaster | |
parent | 5cbe935c9d6046f5600ff2e083b4bae6ee1f4aa2 (diff) | |
download | postgresql-6bc8ef0b7f1f1df3998745a66e1790e27424aa0c.tar.gz postgresql-6bc8ef0b7f1f1df3998745a66e1790e27424aa0c.zip |
Add new GUC, max_worker_processes, limiting number of bgworkers.
In 9.3, there's no particular limit on the number of bgworkers;
instead, we just count up the number that are actually registered,
and use that to set MaxBackends. However, that approach causes
problems for Hot Standby, which needs both MaxBackends and the
size of the lock table to be the same on the standby as on the
master, yet it may not be desirable to run the same bgworkers in
both places. 9.3 handles that by failing to notice the problem,
which will probably work fine in nearly all cases anyway, but is
not theoretically sound.
A further problem with simply counting the number of registered
workers is that new workers can't be registered without a
postmaster restart. This is inconvenient for administrators,
since bouncing the postmaster causes an interruption of service.
Moreover, there are a number of applications for background
processes where, by necessity, the background process must be
started on the fly (e.g. parallel query). While this patch
doesn't actually make it possible to register new background
workers after startup time, it's a necessary prerequisite.
Patch by me. Review by Michael Paquier.
Diffstat (limited to 'src/backend/postmaster')
-rw-r--r-- | src/backend/postmaster/postmaster.c | 54 |
1 files changed, 6 insertions, 48 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 15fd4c90eaa..e3b32cbe080 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -402,7 +402,6 @@ static void reaper(SIGNAL_ARGS); static void sigusr1_handler(SIGNAL_ARGS); static void startup_die(SIGNAL_ARGS); static void dummy_handler(SIGNAL_ARGS); -static int GetNumRegisteredBackgroundWorkers(int flags); static void StartupPacketTimeoutHandler(void); static void CleanupBackend(int pid, int exitstatus); static bool CleanupBackgroundWorker(int pid, int exitstatus); @@ -5212,7 +5211,7 @@ int MaxLivePostmasterChildren(void) { return 2 * (MaxConnections + autovacuum_max_workers + 1 + - GetNumRegisteredBackgroundWorkers(0)); + max_worker_processes); } /* @@ -5226,7 +5225,6 @@ RegisterBackgroundWorker(BackgroundWorker *worker) { RegisteredBgWorker *rw; int namelen = strlen(worker->bgw_name); - static int maxworkers; static int numworkers = 0; #ifdef EXEC_BACKEND @@ -5238,11 +5236,6 @@ RegisterBackgroundWorker(BackgroundWorker *worker) static int BackgroundWorkerCookie = 1; #endif - /* initialize upper limit on first call */ - if (numworkers == 0) - maxworkers = MAX_BACKENDS - - (MaxConnections + autovacuum_max_workers + 1); - if (!IsUnderPostmaster) ereport(LOG, (errmsg("registering background worker: %s", worker->bgw_name))); @@ -5298,17 +5291,17 @@ RegisterBackgroundWorker(BackgroundWorker *worker) /* * Enforce maximum number of workers. Note this is overly restrictive: we * could allow more non-shmem-connected workers, because these don't count - * towards the MAX_BACKENDS limit elsewhere. This doesn't really matter - * for practical purposes; several million processes would need to run on - * a single server. + * towards the MAX_BACKENDS limit elsewhere. For now, it doesn't seem + * important to relax this restriction. */ - if (++numworkers > maxworkers) + if (++numworkers > max_worker_processes) { ereport(LOG, (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), errmsg("too many background workers"), errdetail("Up to %d background workers can be registered with the current settings.", - maxworkers))); + max_worker_processes), + errhint("Consider increasing the configuration parameter \"max_worker_processes\"."))); return; } @@ -5589,41 +5582,6 @@ do_start_bgworker(void) proc_exit(0); } -/* - * Return the number of background workers registered that have at least - * one of the passed flag bits set. - */ -static int -GetNumRegisteredBackgroundWorkers(int flags) -{ - slist_iter iter; - int count = 0; - - slist_foreach(iter, &BackgroundWorkerList) - { - RegisteredBgWorker *rw; - - rw = slist_container(RegisteredBgWorker, rw_lnode, iter.cur); - - if (flags != 0 && - !(rw->rw_worker.bgw_flags & flags)) - continue; - - count++; - } - - return count; -} - -/* - * Return the number of bgworkers that need to have PGPROC entries. - */ -int -GetNumShmemAttachedBgworkers(void) -{ - return GetNumRegisteredBackgroundWorkers(BGWORKER_SHMEM_ACCESS); -} - #ifdef EXEC_BACKEND static pid_t bgworker_forkexec(int cookie) |