Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rIChK-006xZq-JX for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Dec 2023 19:02:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rIChI-00EoKJ-Uf for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Dec 2023 19:02:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rIChI-00EoK9-KJ for pgsql-hackers@lists.postgresql.org; Tue, 26 Dec 2023 19:02:36 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rIChF-00CK79-V6 for pgsql-hackers@lists.postgresql.org; Tue, 26 Dec 2023 19:02:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3BQJ2Xlg2089236 for ; Tue, 26 Dec 2023 14:02:33 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Two small bugs in guc.c MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2089206.1703617322.0@sss.pgh.pa.us> Date: Tue, 26 Dec 2023 14:02:33 -0500 Message-ID: <2089235.1703617353@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2089206.1703617322.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable I investigated the report at [1] about pg_file_settings not reporting invalid values of "log_connections". It turns out it's broken for PGC_BACKEND and PGC_SU_BACKEND parameters, but not other ones. The cause is a bit of premature optimization in this logic: * If a PGC_BACKEND or PGC_SU_BACKEND parameter is changed= in * the config file, we want to accept the new value in the * postmaster (whence it will propagate to * subsequently-started backends), but ignore it in existi= ng * backends. ... Upon detecting that case, set_config_option just returns -1 immediately without bothering to validate the value. It should check for invalid input before returning -1, which we can mechanize with a one-line fix: - return -1; + changeVal =3D false; While studying this, I also noted that the bit to prevent changes in parallel workers seems seriously broken: if (IsInParallelMode() && changeVal && action !=3D GUC_ACTION_SAVE) ereport(elevel, (errcode(ERRCODE_INVALID_TRANSACTION_STATE), errmsg("cannot set parameters during a parallel operation= "))); This is evidently assuming that ereport() won't return, which seems like a very dubious assumption given the various values that elevel can have. Maybe it's accidentally true -- I don't recall any reports of trouble here -- but it sure looks fragile. Hence, proposed patch attached. regards, tom lane [1] https://www.postgresql.org/message-id/flat/CAK30z9T9gaF_isNquccZxi7agX= CSjPjMsFXiifmkfu4VpZguxw%40mail.gmail.com ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="v1-fix-set_config_option-logic-bugs.patch"; charset="us-ascii" Content-ID: <2089206.1703617322.2@sss.pgh.pa.us> Content-Description: v1-fix-set_config_option-logic-bugs.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 959a1c76bf..4126b90ad7 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -3412,9 +3412,12 @@ set_config_with_handle(const char *name, config_han= dle *handle, * Other changes might need to affect other workers, so forbid them. */ if (IsInParallelMode() && changeVal && action !=3D GUC_ACTION_SAVE) + { ereport(elevel, (errcode(ERRCODE_INVALID_TRANSACTION_STATE), errmsg("cannot set parameters during a parallel operation"))); + return -1; + } = /* if handle is specified, no need to look up option */ if (!handle) @@ -3513,7 +3516,9 @@ set_config_with_handle(const char *name, config_hand= le *handle, * postmaster (whence it will propagate to * subsequently-started backends), but ignore it in existing * backends. This is a tad klugy, but necessary because we - * don't re-read the config file during backend start. + * don't re-read the config file during backend start. Handle + * this by clearing changeVal but continuing, since we do want + * to report incorrect values. * * In EXEC_BACKEND builds, this works differently: we load all * non-default settings from the CONFIG_EXEC_PARAMS file @@ -3526,7 +3531,7 @@ set_config_with_handle(const char *name, config_hand= le *handle, * applies. */ if (IsUnderPostmaster && !is_reload) - return -1; + changeVal =3D false; } else if (context !=3D PGC_POSTMASTER && context !=3D PGC_BACKEND && ------- =_aaaaaaaaaa0--