pgsql: Remove check hooks for GUCs that contribute to MaxBackends. - Mailing list pgsql-committers

From Nathan Bossart
Subject pgsql: Remove check hooks for GUCs that contribute to MaxBackends.
Date
Msg-id E1sPosA-000SBr-6p@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0b1fe1413ea84a381489ed1d1f718cb710229ab3

Modified Files
--------------
src/backend/utils/init/postinit.c   | 57 +++++--------------------------------
src/backend/utils/misc/guc_tables.c |  8 +++---
src/include/utils/guc_hooks.h       |  6 ----
3 files changed, 11 insertions(+), 60 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Improve PL/Tcl's method for choosing Tcl names of procedures.
Next
From: Bruce Momjian
Date:
Subject: pgsql: doc PG 17 relnotes: fix psql connection cancelation item