pgsql: Remove check hooks for GUCs that contribute to MaxBackends.

From: Nathan Bossart <nathan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Remove check hooks for GUCs that contribute to MaxBackends.
Date: 2024-07-05 19:45:35
Message-ID: E1sPosA-000SBr-6p@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2024-07-05 20:52:24 pgsql: doc PG 17 relnotes: fix psql connection cancelation item
Previous Message Tom Lane 2024-07-05 18:14:58 pgsql: Improve PL/Tcl's method for choosing Tcl names of procedures.