]> granicus.if.org Git - postgresql/commitdiff
Disallow setting client_min_messages higher than ERROR.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Nov 2018 22:33:25 +0000 (17:33 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Nov 2018 22:33:44 +0000 (17:33 -0500)
Previously it was possible to set client_min_messages to FATAL or PANIC,
which had the effect of suppressing transmission of regular ERROR messages
to the client.  Perhaps that seemed like a useful option in the past, but
the trouble with it is that it breaks guarantees that are explicitly made
in our FE/BE protocol spec about how a query cycle can end.  While libpq
and psql manage to cope with the omission, that's mostly because they
are not very bright; client libraries that have more semantic knowledge
are likely to get confused.  Notably, pgODBC doesn't behave very sanely.
Let's fix this by getting rid of the ability to set client_min_messages
above ERROR.

In HEAD, just remove the FATAL and PANIC options from the set of allowed
enum values for client_min_messages.  (This change also affects
trace_recovery_messages, but that's OK since these aren't useful values
for that variable either.)

In the back branches, there was concern that rejecting these values might
break applications that are explicitly setting things that way.  I'm
pretty skeptical of that argument, but accommodate it by accepting these
values and then internally setting the variable to ERROR anyway.

In all branches, this allows a couple of tiny simplifications in the
logic in elog.c, so do that.

Also respond to the point that was made that client_min_messages has
exactly nothing to do with the server's logging behavior, and therefore
does not belong in the "When To Log" subsection of the documentation.
The "Statement Behavior" subsection is a better match, so move it there.

Jonah Harris and Tom Lane

Discussion: https://postgr.es/m/7809.1541521180@sss.pgh.pa.us
Discussion: https://postgr.es/m/15479-ef0f4cc2fd995ca2@postgresql.org

doc/src/sgml/config.sgml
src/backend/utils/error/elog.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample

index 347abbe4c9b5be46841d0e2a91faa6205e00b962..f5271609013a33b7b368af193eecc2f01e682a37 100644 (file)
@@ -5077,28 +5077,6 @@ local0.*    /var/log/postgresql
 
      <variablelist>
 
-     <varlistentry id="guc-client-min-messages" xreflabel="client_min_messages">
-      <term><varname>client_min_messages</varname> (<type>enum</type>)
-      <indexterm>
-       <primary><varname>client_min_messages</varname> configuration parameter</primary>
-      </indexterm>
-      </term>
-      <listitem>
-       <para>
-        Controls which message levels are sent to the client.
-        Valid values are <literal>DEBUG5</literal>,
-        <literal>DEBUG4</literal>, <literal>DEBUG3</literal>, <literal>DEBUG2</literal>,
-        <literal>DEBUG1</literal>, <literal>LOG</literal>, <literal>NOTICE</literal>,
-        <literal>WARNING</literal>, <literal>ERROR</literal>, <literal>FATAL</literal>,
-        and <literal>PANIC</literal>.  Each level
-        includes all the levels that follow it.  The later the level,
-        the fewer messages are sent.  The default is
-        <literal>NOTICE</literal>.  Note that <literal>LOG</literal> has a different
-        rank here than in <varname>log_min_messages</varname>.
-       </para>
-      </listitem>
-     </varlistentry>
-
      <varlistentry id="guc-log-min-messages" xreflabel="log_min_messages">
       <term><varname>log_min_messages</varname> (<type>enum</type>)
       <indexterm>
@@ -5116,7 +5094,7 @@ local0.*    /var/log/postgresql
         follow it.  The later the level, the fewer messages are sent
         to the log.  The default is <literal>WARNING</literal>.  Note that
         <literal>LOG</literal> has a different rank here than in
-        <varname>client_min_messages</varname>.
+        <xref linkend="guc-client-min-messages"/>.
         Only superusers can change this setting.
        </para>
       </listitem>
@@ -6437,6 +6415,27 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
      <title>Statement Behavior</title>
      <variablelist>
 
+     <varlistentry id="guc-client-min-messages" xreflabel="client_min_messages">
+      <term><varname>client_min_messages</varname> (<type>enum</type>)
+      <indexterm>
+       <primary><varname>client_min_messages</varname> configuration parameter</primary>
+      </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Controls which message levels are sent to the client.
+        Valid values are <literal>DEBUG5</literal>,
+        <literal>DEBUG4</literal>, <literal>DEBUG3</literal>, <literal>DEBUG2</literal>,
+        <literal>DEBUG1</literal>, <literal>LOG</literal>, <literal>NOTICE</literal>,
+        <literal>WARNING</literal>, and <literal>ERROR</literal>.
+        Each level includes all the levels that follow it.  The later the level,
+        the fewer messages are sent.  The default is
+        <literal>NOTICE</literal>.  Note that <literal>LOG</literal> has a different
+        rank here than in <xref linkend="guc-log-min-messages"/>.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-search-path" xreflabel="search_path">
       <term><varname>search_path</varname> (<type>string</type>)
       <indexterm>
index 16531f7a0f1434810eaf7e5697884345db657bde..9dc7163a40a0382e3ea325c0f200f090020194b2 100644 (file)
@@ -472,9 +472,7 @@ errfinish(int dummy,...)
         * progress, so that we can report the message before dying.  (Without
         * this, pq_putmessage will refuse to send the message at all, which is
         * what we want for NOTICE messages, but not for fatal exits.) This hack
-        * is necessary because of poor design of old-style copy protocol.  Note
-        * we must do this even if client is fool enough to have set
-        * client_min_messages above FATAL, so don't look at output_to_client.
+        * is necessary because of poor design of old-style copy protocol.
         */
        if (elevel >= FATAL && whereToSendOutput == DestRemote)
                pq_endcopyout(true);
@@ -1758,12 +1756,7 @@ pg_re_throw(void)
                else
                        edata->output_to_server = (FATAL >= log_min_messages);
                if (whereToSendOutput == DestRemote)
-               {
-                       if (ClientAuthInProgress)
-                               edata->output_to_client = true;
-                       else
-                               edata->output_to_client = (FATAL >= client_min_messages);
-               }
+                       edata->output_to_client = true;
 
                /*
                 * We can use errfinish() for the rest, but we don't want it to call
index 7ca7e8820debd2365fffbc11c2ed45bbb944b5b7..7497a282bfb84c057e46b81b6b09ddf31f88ead8 100644 (file)
@@ -164,6 +164,7 @@ static int  syslog_facility = 0;
 static void assign_syslog_facility(int newval, void *extra);
 static void assign_syslog_ident(const char *newval, void *extra);
 static void assign_session_replication_role(int newval, void *extra);
+static bool check_client_min_messages(int *newval, void **extra, GucSource source);
 static bool check_temp_buffers(int *newval, void **extra, GucSource source);
 static bool check_bonjour(bool *newval, void **extra, GucSource source);
 static bool check_ssl(bool *newval, void **extra, GucSource source);
@@ -3912,14 +3913,14 @@ static struct config_enum ConfigureNamesEnum[] =
        },
 
        {
-               {"client_min_messages", PGC_USERSET, LOGGING_WHEN,
+               {"client_min_messages", PGC_USERSET, CLIENT_CONN_STATEMENT,
                        gettext_noop("Sets the message levels that are sent to the client."),
                        gettext_noop("Each level includes all the levels that follow it. The later"
                                                 " the level, the fewer messages are sent.")
                },
                &client_min_messages,
                NOTICE, client_message_level_options,
-               NULL, NULL, NULL
+               check_client_min_messages, NULL, NULL
        },
 
        {
@@ -10410,6 +10411,20 @@ assign_session_replication_role(int newval, void *extra)
                ResetPlanCache();
 }
 
+static bool
+check_client_min_messages(int *newval, void **extra, GucSource source)
+{
+       /*
+        * We disallow setting client_min_messages above ERROR, because not
+        * sending an ErrorResponse message for an error breaks the FE/BE
+        * protocol.  However, for backwards compatibility, we still accept FATAL
+        * or PANIC as input values, and then adjust here.
+        */
+       if (*newval > ERROR)
+               *newval = ERROR;
+       return true;
+}
+
 static bool
 check_temp_buffers(int *newval, void **extra, GucSource source)
 {
index 163e3879b2e567d84031f7093fe7afae950e1fca..14527634bab34474c1c452db239741f5bad0eee9 100644 (file)
 
 # - When to Log -
 
-#client_min_messages = notice          # values in order of decreasing detail:
-                                       #   debug5
-                                       #   debug4
-                                       #   debug3
-                                       #   debug2
-                                       #   debug1
-                                       #   log
-                                       #   notice
-                                       #   warning
-                                       #   error
-
 #log_min_messages = warning            # values in order of decreasing detail:
                                        #   debug5
                                        #   debug4
 
 # - Statement Behavior -
 
+#client_min_messages = notice          # values in order of decreasing detail:
+                                       #   debug5
+                                       #   debug4
+                                       #   debug3
+                                       #   debug2
+                                       #   debug1
+                                       #   log
+                                       #   notice
+                                       #   warning
+                                       #   error
 #search_path = '"$user", public'       # schema names
 #row_security = on
 #default_tablespace = ''               # a tablespace name, '' uses the default