Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3d360e2

Browse files
committed
Disallow setting client_min_messages higher than ERROR.
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
1 parent 705d433 commit 3d360e2

File tree

4 files changed

+37
-47
lines changed

4 files changed

+37
-47
lines changed

doc/src/sgml/config.sgml

+22-23
Original file line numberDiff line numberDiff line change
@@ -5111,28 +5111,6 @@ local0.* /var/log/postgresql
51115111

51125112
<variablelist>
51135113

5114-
<varlistentry id="guc-client-min-messages" xreflabel="client_min_messages">
5115-
<term><varname>client_min_messages</varname> (<type>enum</type>)
5116-
<indexterm>
5117-
<primary><varname>client_min_messages</varname> configuration parameter</primary>
5118-
</indexterm>
5119-
</term>
5120-
<listitem>
5121-
<para>
5122-
Controls which message levels are sent to the client.
5123-
Valid values are <literal>DEBUG5</literal>,
5124-
<literal>DEBUG4</literal>, <literal>DEBUG3</literal>, <literal>DEBUG2</literal>,
5125-
<literal>DEBUG1</literal>, <literal>LOG</literal>, <literal>NOTICE</literal>,
5126-
<literal>WARNING</literal>, <literal>ERROR</literal>, <literal>FATAL</literal>,
5127-
and <literal>PANIC</literal>. Each level
5128-
includes all the levels that follow it. The later the level,
5129-
the fewer messages are sent. The default is
5130-
<literal>NOTICE</literal>. Note that <literal>LOG</literal> has a different
5131-
rank here than in <varname>log_min_messages</varname>.
5132-
</para>
5133-
</listitem>
5134-
</varlistentry>
5135-
51365114
<varlistentry id="guc-log-min-messages" xreflabel="log_min_messages">
51375115
<term><varname>log_min_messages</varname> (<type>enum</type>)
51385116
<indexterm>
@@ -5150,7 +5128,7 @@ local0.* /var/log/postgresql
51505128
follow it. The later the level, the fewer messages are sent
51515129
to the log. The default is <literal>WARNING</literal>. Note that
51525130
<literal>LOG</literal> has a different rank here than in
5153-
<varname>client_min_messages</varname>.
5131+
<xref linkend="guc-client-min-messages"/>.
51545132
Only superusers can change this setting.
51555133
</para>
51565134
</listitem>
@@ -6471,6 +6449,27 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
64716449
<title>Statement Behavior</title>
64726450
<variablelist>
64736451

6452+
<varlistentry id="guc-client-min-messages" xreflabel="client_min_messages">
6453+
<term><varname>client_min_messages</varname> (<type>enum</type>)
6454+
<indexterm>
6455+
<primary><varname>client_min_messages</varname> configuration parameter</primary>
6456+
</indexterm>
6457+
</term>
6458+
<listitem>
6459+
<para>
6460+
Controls which message levels are sent to the client.
6461+
Valid values are <literal>DEBUG5</literal>,
6462+
<literal>DEBUG4</literal>, <literal>DEBUG3</literal>, <literal>DEBUG2</literal>,
6463+
<literal>DEBUG1</literal>, <literal>LOG</literal>, <literal>NOTICE</literal>,
6464+
<literal>WARNING</literal>, and <literal>ERROR</literal>.
6465+
Each level includes all the levels that follow it. The later the level,
6466+
the fewer messages are sent. The default is
6467+
<literal>NOTICE</literal>. Note that <literal>LOG</literal> has a different
6468+
rank here than in <xref linkend="guc-log-min-messages"/>.
6469+
</para>
6470+
</listitem>
6471+
</varlistentry>
6472+
64746473
<varlistentry id="guc-search-path" xreflabel="search_path">
64756474
<term><varname>search_path</varname> (<type>string</type>)
64766475
<indexterm>

src/backend/utils/error/elog.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,7 @@ errfinish(int dummy,...)
469469
* progress, so that we can report the message before dying. (Without
470470
* this, pq_putmessage will refuse to send the message at all, which is
471471
* what we want for NOTICE messages, but not for fatal exits.) This hack
472-
* is necessary because of poor design of old-style copy protocol. Note
473-
* we must do this even if client is fool enough to have set
474-
* client_min_messages above FATAL, so don't look at output_to_client.
472+
* is necessary because of poor design of old-style copy protocol.
475473
*/
476474
if (elevel >= FATAL && whereToSendOutput == DestRemote)
477475
pq_endcopyout(true);
@@ -1747,12 +1745,7 @@ pg_re_throw(void)
17471745
else
17481746
edata->output_to_server = (FATAL >= log_min_messages);
17491747
if (whereToSendOutput == DestRemote)
1750-
{
1751-
if (ClientAuthInProgress)
1752-
edata->output_to_client = true;
1753-
else
1754-
edata->output_to_client = (FATAL >= client_min_messages);
1755-
}
1748+
edata->output_to_client = true;
17561749

17571750
/*
17581751
* We can use errfinish() for the rest, but we don't want it to call

src/backend/utils/misc/guc.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ static const struct config_enum_entry bytea_output_options[] = {
215215

216216
/*
217217
* We have different sets for client and server message level options because
218-
* they sort slightly different (see "log" level)
218+
* they sort slightly different (see "log" level), and because "fatal"/"panic"
219+
* aren't sensible for client_min_messages.
219220
*/
220221
static const struct config_enum_entry client_message_level_options[] = {
221222
{"debug5", DEBUG5, false},
@@ -229,8 +230,6 @@ static const struct config_enum_entry client_message_level_options[] = {
229230
{"notice", NOTICE, false},
230231
{"warning", WARNING, false},
231232
{"error", ERROR, false},
232-
{"fatal", FATAL, true},
233-
{"panic", PANIC, true},
234233
{NULL, 0, false}
235234
};
236235

@@ -3924,7 +3923,7 @@ static struct config_enum ConfigureNamesEnum[] =
39243923
},
39253924

39263925
{
3927-
{"client_min_messages", PGC_USERSET, LOGGING_WHEN,
3926+
{"client_min_messages", PGC_USERSET, CLIENT_CONN_STATEMENT,
39283927
gettext_noop("Sets the message levels that are sent to the client."),
39293928
gettext_noop("Each level includes all the levels that follow it. The later"
39303929
" the level, the fewer messages are sent.")

src/backend/utils/misc/postgresql.conf.sample

+10-11
Original file line numberDiff line numberDiff line change
@@ -406,17 +406,6 @@
406406

407407
# - When to Log -
408408

409-
#client_min_messages = notice # values in order of decreasing detail:
410-
# debug5
411-
# debug4
412-
# debug3
413-
# debug2
414-
# debug1
415-
# log
416-
# notice
417-
# warning
418-
# error
419-
420409
#log_min_messages = warning # values in order of decreasing detail:
421410
# debug5
422411
# debug4
@@ -561,6 +550,16 @@
561550

562551
# - Statement Behavior -
563552

553+
#client_min_messages = notice # values in order of decreasing detail:
554+
# debug5
555+
# debug4
556+
# debug3
557+
# debug2
558+
# debug1
559+
# log
560+
# notice
561+
# warning
562+
# error
564563
#search_path = '"$user", public' # schema names
565564
#row_security = on
566565
#default_tablespace = '' # a tablespace name, '' uses the default

0 commit comments

Comments
 (0)