Skip to content

Commit 2d36a5e

Browse files
committed
Provide a log_level setting for auto_explain
Up to now the log level has been hardcoded at LOG. A new auto_explain.log_level setting allows that to be modified. Discussion: https://postgr.es/m/CAPPfruyZh+snR2AdmutrA0B_caj=yWZkLqxUTZYNjJCaQ_wKQg@mail.gmail.com Tom Dunstan and Andrew Dunstan Reviewed by Daniel Gustafsson
1 parent 6574f19 commit 2d36a5e

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

contrib/auto_explain/auto_explain.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static bool auto_explain_log_buffers = false;
2828
static bool auto_explain_log_triggers = false;
2929
static bool auto_explain_log_timing = true;
3030
static int auto_explain_log_format = EXPLAIN_FORMAT_TEXT;
31+
static int auto_explain_log_level = LOG;
3132
static bool auto_explain_log_nested_statements = false;
3233
static double auto_explain_sample_rate = 1;
3334

@@ -39,6 +40,20 @@ static const struct config_enum_entry format_options[] = {
3940
{NULL, 0, false}
4041
};
4142

43+
static const struct config_enum_entry loglevel_options[] = {
44+
{"debug5", DEBUG5, false},
45+
{"debug4", DEBUG4, false},
46+
{"debug3", DEBUG3, false},
47+
{"debug2", DEBUG2, false},
48+
{"debug1", DEBUG1, false},
49+
{"debug", DEBUG2, true},
50+
{"info", INFO, false},
51+
{"notice", NOTICE, false},
52+
{"warning", WARNING, false},
53+
{"log", LOG, false},
54+
{NULL, 0, false}
55+
};
56+
4257
/* Current nesting depth of ExecutorRun calls */
4358
static int nesting_level = 0;
4459

@@ -141,6 +156,18 @@ _PG_init(void)
141156
NULL,
142157
NULL);
143158

159+
DefineCustomEnumVariable("auto_explain.log_level",
160+
"Log level for the plan.",
161+
NULL,
162+
&auto_explain_log_level,
163+
LOG,
164+
loglevel_options,
165+
PGC_SUSET,
166+
0,
167+
NULL,
168+
NULL,
169+
NULL);
170+
144171
DefineCustomBoolVariable("auto_explain.log_nested_statements",
145172
"Log nested statements.",
146173
NULL,
@@ -353,7 +380,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
353380
* reported. This isn't ideal but trying to do it here would
354381
* often result in duplication.
355382
*/
356-
ereport(LOG,
383+
ereport(auto_explain_log_level,
357384
(errmsg("duration: %.3f ms plan:\n%s",
358385
msec, es->str->data),
359386
errhidestmt(true)));

doc/src/sgml/auto-explain.sgml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,27 @@ LOAD 'auto_explain';
187187
</listitem>
188188
</varlistentry>
189189

190+
<varlistentry>
191+
<term>
192+
<varname>auto_explain.log_level</varname> (<type>enum</type>)
193+
<indexterm>
194+
<primary><varname>auto_explain.log_level</> configuration parameter</primary>
195+
</indexterm>
196+
</term>
197+
<listitem>
198+
<para>
199+
<varname>auto_explain.log_level</varname> selects the log level at which
200+
auto_explain will log the query plan.
201+
Valid values are <literal>DEBUG5</literal>, <literal>DEBUG4</literal>,
202+
<literal>DEBUG3</literal>, <literal>DEBUG2</literal>,
203+
<literal>DEBUG1</literal>, <literal>INFO</literal>,
204+
<literal>NOTICE</literal>, <literal>WARNING</literal>,
205+
and <literal>LOG</literal>. The default is <literal>LOG</literal>.
206+
Only superusers can change this setting.
207+
</para>
208+
</listitem>
209+
</varlistentry>
210+
190211
<varlistentry>
191212
<term>
192213
<varname>auto_explain.log_nested_statements</varname> (<type>boolean</type>)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy