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/utils/misc/guc.c | |
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/utils/misc/guc.c')
-rw-r--r-- | src/backend/utils/misc/guc.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 3a7653698d3..d6200616de8 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -190,6 +190,7 @@ static const char *show_tcp_keepalives_idle(void); static const char *show_tcp_keepalives_interval(void); static const char *show_tcp_keepalives_count(void); static bool check_maxconnections(int *newval, void **extra, GucSource source); +static bool check_max_worker_processes(int *newval, void **extra, GucSource source); static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source); static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source); static void assign_effective_io_concurrency(int newval, void *extra); @@ -2159,6 +2160,18 @@ static struct config_int ConfigureNamesInt[] = }, { + {"max_worker_processes", + PGC_POSTMASTER, + RESOURCES_ASYNCHRONOUS, + gettext_noop("Maximum number of concurrent worker processes."), + NULL, + }, + &max_worker_processes, + 8, 1, MAX_BACKENDS, + check_max_worker_processes, NULL, NULL + }, + + { {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE, gettext_noop("Automatic log file rotation will occur after N minutes."), NULL, @@ -8667,8 +8680,8 @@ show_tcp_keepalives_count(void) static bool check_maxconnections(int *newval, void **extra, GucSource source) { - if (*newval + GetNumShmemAttachedBgworkers() + autovacuum_max_workers + 1 > - MAX_BACKENDS) + if (*newval + autovacuum_max_workers + 1 + + max_worker_processes > MAX_BACKENDS) return false; return true; } @@ -8676,8 +8689,15 @@ check_maxconnections(int *newval, void **extra, GucSource source) static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source) { - if (MaxConnections + *newval + 1 + GetNumShmemAttachedBgworkers() > - MAX_BACKENDS) + if (MaxConnections + *newval + 1 + max_worker_processes > MAX_BACKENDS) + return false; + return true; +} + +static bool +check_max_worker_processes(int *newval, void **extra, GucSource source) +{ + if (MaxConnections + autovacuum_max_workers + 1 + *newval > MAX_BACKENDS) return false; return true; } |