calculate-MaxBackends-in-postmaster.patch
text/x-diff
Filename: calculate-MaxBackends-in-postmaster.patch
Type: text/x-diff
Part: 0
Message:
Re: fix bgworkers in EXEC_BACKEND
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/postmaster/postmaster.c | 9 | 8 |
| src/backend/utils/misc/guc.c | 2 | 17 |
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 8f39aec..9dc8bd3 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -499,6 +499,7 @@ typedef struct
bool redirection_done;
bool IsBinaryUpgrade;
int max_safe_fds;
+ int MaxBackends;
#ifdef WIN32
HANDLE PostmasterHandle;
HANDLE initial_signal_pipe;
@@ -897,15 +898,11 @@ PostmasterMain(int argc, char *argv[])
process_shared_preload_libraries();
/*
- * If loadable modules have added background workers, MaxBackends needs to
- * be updated. Do so now by forcing a no-op update of max_connections.
- * XXX This is a pretty ugly way to do it, but it doesn't seem worth
- * introducing a new entry point in guc.c to do it in a cleaner fashion.
+ * Now that loadable modules have had their chance to register background
+ * workers, calculate MaxBackends.
*/
- if (GetNumShmemAttachedBgworkers() > 0)
- SetConfigOption("max_connections",
- GetConfigOption("max_connections", false, false),
- PGC_POSTMASTER, PGC_S_OVERRIDE);
+ MaxBackends = MaxConnections + autovacuum_max_workers + 1 +
+ GetNumShmemAttachedBgworkers();
/*
* Establish input sockets.
@@ -5836,6 +5833,8 @@ save_backend_variables(BackendParameters *param, Port *port,
param->IsBinaryUpgrade = IsBinaryUpgrade;
param->max_safe_fds = max_safe_fds;
+ param->MaxBackends = MaxBackends;
+
#ifdef WIN32
param->PostmasterHandle = PostmasterHandle;
if (!write_duplicated_handle(¶m->initial_signal_pipe,
@@ -6061,6 +6060,8 @@ restore_backend_variables(BackendParameters *param, Port *port)
IsBinaryUpgrade = param->IsBinaryUpgrade;
max_safe_fds = param->max_safe_fds;
+ MaxBackends = param->MaxBackends;
+
#ifdef WIN32
PostmasterHandle = param->PostmasterHandle;
pgwin32_initial_signal_pipe = param->initial_signal_pipe;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 2cf34ce..eca6a60 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -199,9 +199,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 void assign_maxconnections(int newval, void *extra);
static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource source);
-static void assign_autovacuum_max_workers(int newval, void *extra);
static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
static void assign_effective_io_concurrency(int newval, void *extra);
static void assign_pgstat_temp_directory(const char *newval, void *extra);
@@ -1615,7 +1613,7 @@ static struct config_int ConfigureNamesInt[] =
},
&MaxConnections,
100, 1, MAX_BACKENDS,
- check_maxconnections, assign_maxconnections, NULL
+ check_maxconnections, NULL, NULL
},
{
@@ -2290,7 +2288,7 @@ static struct config_int ConfigureNamesInt[] =
},
&autovacuum_max_workers,
3, 1, MAX_BACKENDS,
- check_autovacuum_max_workers, assign_autovacuum_max_workers, NULL
+ check_autovacuum_max_workers, NULL, NULL
},
{
@@ -8636,13 +8634,6 @@ check_maxconnections(int *newval, void **extra, GucSource source)
return true;
}
-static void
-assign_maxconnections(int newval, void *extra)
-{
- MaxBackends = newval + autovacuum_max_workers + 1 +
- GetNumShmemAttachedBgworkers();
-}
-
static bool
check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
{
@@ -8652,12 +8643,6 @@ check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
return true;
}
-static void
-assign_autovacuum_max_workers(int newval, void *extra)
-{
- MaxBackends = MaxConnections + newval + 1 + GetNumShmemAttachedBgworkers();
-}
-
static bool
check_effective_io_concurrency(int *newval, void **extra, GucSource source)
{