Silence extra logging when using "postgres -C" on runtime-computed GUCs
authorMichael Paquier <[email protected]>
Wed, 11 May 2022 05:21:06 +0000 (14:21 +0900)
committerMichael Paquier <[email protected]>
Wed, 11 May 2022 05:21:06 +0000 (14:21 +0900)
Presently, the server may emit a variety of log messages when inspecting
a runtime-computed GUC, mostly in the shape of one LOG message with the
default configuration, related to the startup sequence launched as such
GUCs require a load of the control file and of external shared
libraries.

For example, the server will always emit a "database system is shut
down" LOG (unless the user has set log_min_messages higher than LOG),
which is an annoying behavior as "postgres -C" is expected to only emit
in its output the parameter value we are looking for.  The parameter
value is sent to stdout, while the logs are sent to stderr so we could
recommend to use a redirection, but there was not much love for this
workaround either.

To avoid such extra log messages, per discussion, this change sets
log_min_messages to FATAL internally when -C is used on a
runtime-computed GUC (even if set to PANIC in postgresql.conf).  At
FATAL, the user will still receive messages explaining why a GUC value
cannot be inspected, and will know if the command is attempted on a
server already running, something not supported yet for a
runtime-computed GUC.

Reported-by: Magnus Hagander, Bruce Momjian
Author: Nathan Bossart, Michael Paquier
Discussion: https://postgr.es/m/[email protected]

doc/src/sgml/runtime.sgml
src/backend/postmaster/postmaster.c

index 4465c876b18791c800661c1f6108df47c2acddab..62cec614d3730c73c230bb1ff2231233f23321aa 100644 (file)
@@ -1448,7 +1448,7 @@ export PG_OOM_ADJUST_VALUE=0
     server must be shut down to view this runtime-computed parameter.
     This might look like:
 <programlisting>
-$ <userinput>postgres -D $PGDATA -C shared_memory_size_in_huge_pages 2> /dev/null</userinput>
+$ <userinput>postgres -D $PGDATA -C shared_memory_size_in_huge_pages</userinput>
 3170
 $ <userinput>grep ^Hugepagesize /proc/meminfo</userinput>
 Hugepagesize:       2048 kB
index ce4007bb2c70f232c645f4dc470afdcae866d8c3..8e61b3471ca442fb53f30613c6e0f5822e2b45ec 100644 (file)
@@ -913,6 +913,16 @@ PostmasterMain(int argc, char *argv[])
                        puts(config_val ? config_val : "");
                        ExitPostmaster(0);
                }
+
+               /*
+                * A runtime-computed GUC will be printed later on.  As we initialize
+                * a server startup sequence, silence any log messages that may show
+                * up in the output generated.  FATAL and more severe messages are
+                * useful to show, even if one would only expect at least PANIC.  LOG
+                * entries are hidden.
+                */
+               SetConfigOption("log_min_messages", "FATAL", PGC_INTERNAL,
+                                               PGC_S_OVERRIDE);
        }
 
        /* Verify that DataDir looks reasonable */