Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b1fe14

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 hookthat verifies the sum of those GUCs does not exceed a hard-codedlimit (see the comment for MAX_BACKENDS in postmaster.h). Ingeneral, the hooks effectively guard against egregiousmisconfigurations.However, this approach has some problems. Since these check hooksare called as each GUC is assigned its user-specified value, onlyone of the hooks will be called with all the relevant GUCs set. Ifone or more of the user-specified values are less than the initialvalues of the GUCs' underlying variables, false positives canoccur.Furthermore, the error message emitted when one of the check hooksfails 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": 10000Fortunately, there is an extra copy of this check inInitializeMaxBackends() that we can rely on, so this commit removesthe aforementioned GUC check hooks in favor of that one. It alsoenhances the error message to clearly show the values of therelevant GUCs and the hard-coded limit their sum may not exceed.The downside of this change is that server startup progressesfurther before failing due to such misconfigurations (thus takinglonger), but these failures are expected to be rare, so we don'tanticipate any real harm in practice.Reviewed-by: Tom LaneDiscussion:https://postgr.es/m/ZnMr2k-Nk5vj7T7H%40nathan
1 parentba8f00e commit0b1fe14

File tree

3 files changed

+11
-60
lines changed

3 files changed

+11
-60
lines changed

‎src/backend/utils/init/postinit.c

Lines changed: 7 additions & 50 deletions
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,GucSourcesource)
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,GucSourcesource)
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,GucSourcesource)
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,GucSourcesource)
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ extern bool check_application_name(char **newval, void **extra,
2929
GucSourcesource);
3030
externvoidassign_application_name(constchar*newval,void*extra);
3131
externconstchar*show_archive_command(void);
32-
externboolcheck_autovacuum_max_workers(int*newval,void**extra,
33-
GucSourcesource);
3432
externboolcheck_autovacuum_work_mem(int*newval,void**extra,
3533
GucSourcesource);
3634
externboolcheck_vacuum_buffer_usage_limit(int*newval,void**extra,
@@ -84,13 +82,9 @@ extern const char *show_log_timezone(void);
8482
externboolcheck_maintenance_io_concurrency(int*newval,void**extra,
8583
GucSourcesource);
8684
externvoidassign_maintenance_io_concurrency(intnewval,void*extra);
87-
externboolcheck_max_connections(int*newval,void**extra,GucSourcesource);
88-
externboolcheck_max_wal_senders(int*newval,void**extra,GucSourcesource);
8985
externboolcheck_max_slot_wal_keep_size(int*newval,void**extra,
9086
GucSourcesource);
9187
externvoidassign_max_wal_size(intnewval,void*extra);
92-
externboolcheck_max_worker_processes(int*newval,void**extra,
93-
GucSourcesource);
9488
externboolcheck_max_stack_depth(int*newval,void**extra,GucSourcesource);
9589
externvoidassign_max_stack_depth(intnewval,void*extra);
9690
externboolcheck_multixact_member_buffers(int*newval,void**extra,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp