pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
Subject: [PATCH v3 1/1] Silence extra logging with 'postgres -C'.
Date: Mon, 28 Mar 2022 10:12:23 -0700

Presently, the server may emit a variety of extra log messages when inspecting
GUC values.  For example, when inspecting a runtime-computed GUC, the server
will always emit a "database system is shut down" LOG (unless the user has set
log_min_messages higher than LOG).  To avoid these extra log messages, this
change sets log_min_messages to FATAL when -C is used (unless the user has set
it to PANIC).  At FATAL, the user will still receive messages explaining why a
GUC's value cannot be inspected.
---
 src/backend/postmaster/postmaster.c | 34 +++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

inline patch 1: src/backend/postmaster/postmaster.c (+30/-4 lines) download inline-1.patchdiff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 80bb269599..7ee20d7c69 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -897,6 +897,26 @@ PostmasterMain(int argc, char *argv[]) if (output_config_variable != NULL) { + const char *logging_setting; + int flags; + + /* + * Silence any extra log messages when -C is used. Before adjusting + * log_min_messages, we save its value in case the user is inspecting + * it. If we are inspecting a runtime-computed GUC, it is possible that + * a preloaded library's _PG_init() will override our custom setting for + * log_min_messages, but trying to deal with that is probably more + * trouble than it's worth. + * + * If the user has set log_min_messages to PANIC, we leave it at PANIC. + * This has the side effect of silencing helpful FATAL messages (e.g., + * when trying to inspect a runtime-computed GUC on a running server), + * but presumably the user has set it there for good reason. + */ + logging_setting = GetConfigOption("log_min_messages", false, false); + if (log_min_messages < FATAL) + SetConfigOption("log_min_messages", "FATAL", PGC_INTERNAL, PGC_S_OVERRIDE); + /* * If this is a runtime-computed GUC, it hasn't yet been initialized, * and the present value is not useful. However, this is a convenient @@ -908,17 +928,23 @@ PostmasterMain(int argc, char *argv[]) * on running servers for those GUCs, but using this option now would * lead to incorrect results for them. */ - int flags = GetConfigOptionFlags(output_config_variable, true); + flags = GetConfigOptionFlags(output_config_variable, true); if ((flags & GUC_RUNTIME_COMPUTED) == 0) { + const char *config_val; + /* * "-C guc" was specified, so print GUC's value and exit. No * extra permission check is needed because the user is reading - * inside the data dir. + * inside the data dir. If we are inspecting log_min_messages, + * print the saved value. */ - const char *config_val = GetConfigOption(output_config_variable, - false, false); + if (pg_strcasecmp(output_config_variable, "log_min_messages") == 0) + config_val = logging_setting; + else + config_val = GetConfigOption(output_config_variable, + false, false); puts(config_val ? config_val : ""); ExitPostmaster(0); -- 2.25.1
--zYM0uCDKw75PZbzx--

Message-ID: <no-message-id-1987@localhost>
Permalink:  ../no-message-id-1987@localhost/
Also on:    postgresql.org/message-id/no-message-id-1987@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: nathandbossart@gmail.com
  Subject: Re: [PATCH v3 1/1] Silence extra logging with 'postgres -C'.
  In-Reply-To: <no-message-id-1987@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox