Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b1fe14

Browse files
Remove check hooks for GUCs that contribute to MaxBackends.
Each of max_connections, max_worker_processes, autovacuum_max_workers, and max_wal_senders has a GUC check hook that verifies the sum of those GUCs does not exceed a hard-coded limit (see the comment for MAX_BACKENDS in postmaster.h). In general, the hooks effectively guard against egregious misconfigurations. However, this approach has some problems. Since these check hooks are called as each GUC is assigned its user-specified value, only one of the hooks will be called with all the relevant GUCs set. If one or more of the user-specified values are less than the initial values of the GUCs' underlying variables, false positives can occur. Furthermore, the error message emitted when one of the check hooks fails is not tremendously helpful. For example, the command $ pg_ctl -D . start -o "-c max_connections=262100 -c max_wal_senders=10000" fails with the following error: FATAL: invalid value for parameter "max_wal_senders": 10000 Fortunately, there is an extra copy of this check in InitializeMaxBackends() that we can rely on, so this commit removes the aforementioned GUC check hooks in favor of that one. It also enhances the error message to clearly show the values of the relevant GUCs and the hard-coded limit their sum may not exceed. The downside of this change is that server startup progresses further before failing due to such misconfigurations (thus taking longer), but these failures are expected to be rare, so we don't anticipate any real harm in practice. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/ZnMr2k-Nk5vj7T7H%40nathan
1 parent ba8f00e commit 0b1fe14

File tree

3 files changed

+11
-60
lines changed

3 files changed

+11
-60
lines changed

src/backend/utils/init/postinit.c

+7-50
Original file line numberDiff line numberDiff line change
@@ -580,57 +580,14 @@ InitializeMaxBackends(void)
580580
MaxBackends = MaxConnections + autovacuum_max_workers + 1 +
581581
max_worker_processes + max_wal_senders;
582582

583-
/* internal error because the values were all checked previously */
584583
if (MaxBackends > MAX_BACKENDS)
585-
elog(ERROR, "too many backends configured");
586-
}
587-
588-
/*
589-
* GUC check_hook for max_connections
590-
*/
591-
bool
592-
check_max_connections(int *newval, void **extra, GucSource source)
593-
{
594-
if (*newval + autovacuum_max_workers + 1 +
595-
max_worker_processes + max_wal_senders > MAX_BACKENDS)
596-
return false;
597-
return true;
598-
}
599-
600-
/*
601-
* GUC check_hook for autovacuum_max_workers
602-
*/
603-
bool
604-
check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
605-
{
606-
if (MaxConnections + *newval + 1 +
607-
max_worker_processes + max_wal_senders > MAX_BACKENDS)
608-
return false;
609-
return true;
610-
}
611-
612-
/*
613-
* GUC check_hook for max_worker_processes
614-
*/
615-
bool
616-
check_max_worker_processes(int *newval, void **extra, GucSource source)
617-
{
618-
if (MaxConnections + autovacuum_max_workers + 1 +
619-
*newval + max_wal_senders > MAX_BACKENDS)
620-
return false;
621-
return true;
622-
}
623-
624-
/*
625-
* GUC check_hook for max_wal_senders
626-
*/
627-
bool
628-
check_max_wal_senders(int *newval, void **extra, GucSource source)
629-
{
630-
if (MaxConnections + autovacuum_max_workers + 1 +
631-
max_worker_processes + *newval > MAX_BACKENDS)
632-
return false;
633-
return true;
584+
ereport(ERROR,
585+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
586+
errmsg("too many server processes configured"),
587+
errdetail("\"max_connections\" (%d) plus \"autovacuum_max_workers\" (%d) plus \"max_worker_processes\" (%d) plus \"max_wal_senders\" (%d) must be less than %d.",
588+
MaxConnections, autovacuum_max_workers,
589+
max_worker_processes, max_wal_senders,
590+
MAX_BACKENDS)));
634591
}
635592

636593
/*

src/backend/utils/misc/guc_tables.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ struct config_int ConfigureNamesInt[] =
22092209
},
22102210
&MaxConnections,
22112211
100, 1, MAX_BACKENDS,
2212-
check_max_connections, NULL, NULL
2212+
NULL, NULL, NULL
22132213
},
22142214

22152215
{
@@ -2925,7 +2925,7 @@ struct config_int ConfigureNamesInt[] =
29252925
},
29262926
&max_wal_senders,
29272927
10, 0, MAX_BACKENDS,
2928-
check_max_wal_senders, NULL, NULL
2928+
NULL, NULL, NULL
29292929
},
29302930

29312931
{
@@ -3155,7 +3155,7 @@ struct config_int ConfigureNamesInt[] =
31553155
},
31563156
&max_worker_processes,
31573157
8, 0, MAX_BACKENDS,
3158-
check_max_worker_processes, NULL, NULL
3158+
NULL, NULL, NULL
31593159
},
31603160

31613161
{
@@ -3389,7 +3389,7 @@ struct config_int ConfigureNamesInt[] =
33893389
},
33903390
&autovacuum_max_workers,
33913391
3, 1, MAX_BACKENDS,
3392-
check_autovacuum_max_workers, NULL, NULL
3392+
NULL, NULL, NULL
33933393
},
33943394

33953395
{

src/include/utils/guc_hooks.h

-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ extern bool check_application_name(char **newval, void **extra,
2929
GucSource source);
3030
extern void assign_application_name(const char *newval, void *extra);
3131
extern const char *show_archive_command(void);
32-
extern bool check_autovacuum_max_workers(int *newval, void **extra,
33-
GucSource source);
3432
extern bool check_autovacuum_work_mem(int *newval, void **extra,
3533
GucSource source);
3634
extern bool check_vacuum_buffer_usage_limit(int *newval, void **extra,
@@ -84,13 +82,9 @@ extern const char *show_log_timezone(void);
8482
extern bool check_maintenance_io_concurrency(int *newval, void **extra,
8583
GucSource source);
8684
extern void assign_maintenance_io_concurrency(int newval, void *extra);
87-
extern bool check_max_connections(int *newval, void **extra, GucSource source);
88-
extern bool check_max_wal_senders(int *newval, void **extra, GucSource source);
8985
extern bool check_max_slot_wal_keep_size(int *newval, void **extra,
9086
GucSource source);
9187
extern void assign_max_wal_size(int newval, void *extra);
92-
extern bool check_max_worker_processes(int *newval, void **extra,
93-
GucSource source);
9488
extern bool check_max_stack_depth(int *newval, void **extra, GucSource source);
9589
extern void assign_max_stack_depth(int newval, void *extra);
9690
extern bool check_multixact_member_buffers(int *newval, void **extra,

0 commit comments

Comments
 (0)