]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
auto_explain: Add new GUC auto_explain.log_io
authorTomas Vondra <tomas.vondra@postgresql.org>
Tue, 7 Apr 2026 20:49:42 +0000 (22:49 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Tue, 7 Apr 2026 20:49:44 +0000 (22:49 +0200)
Allows enabling the new EXPLAIN "IO" option for auto_explain.

Author: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Lukas Fittl <lukas@fittl.com>
Discussion: https://postgr.es/m/flat/a177a6dd-240b-455a-8f25-aca0b1c08c6e%40vondra.me

contrib/auto_explain/auto_explain.c
doc/src/sgml/auto-explain.sgml

index 6ceae1c69ce01d2ae37b8a189735c1b4979a7db1..9114ced45a7e4dd09f4ad3ac9f8273705b1af491 100644 (file)
@@ -38,6 +38,7 @@ static int    auto_explain_log_parameter_max_length = -1; /* bytes or -1 */
 static bool auto_explain_log_analyze = false;
 static bool auto_explain_log_verbose = false;
 static bool auto_explain_log_buffers = false;
+static bool auto_explain_log_io = false;
 static bool auto_explain_log_wal = false;
 static bool auto_explain_log_triggers = false;
 static bool auto_explain_log_timing = true;
@@ -203,6 +204,17 @@ _PG_init(void)
                                                         NULL,
                                                         NULL);
 
+       DefineCustomBoolVariable("auto_explain.log_io",
+                                                        "Log I/O statistics.",
+                                                        NULL,
+                                                        &auto_explain_log_io,
+                                                        false,
+                                                        PGC_SUSET,
+                                                        0,
+                                                        NULL,
+                                                        NULL,
+                                                        NULL);
+
        DefineCustomBoolVariable("auto_explain.log_wal",
                                                         "Log WAL usage.",
                                                         NULL,
@@ -343,6 +355,8 @@ explain_ExecutorStart(QueryDesc *queryDesc, int eflags)
                                queryDesc->instrument_options |= INSTRUMENT_ROWS;
                        if (auto_explain_log_buffers)
                                queryDesc->instrument_options |= INSTRUMENT_BUFFERS;
+                       if (auto_explain_log_io)
+                               queryDesc->instrument_options |= INSTRUMENT_IO;
                        if (auto_explain_log_wal)
                                queryDesc->instrument_options |= INSTRUMENT_WAL;
                }
@@ -440,6 +454,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
                        es->analyze = (queryDesc->instrument_options && auto_explain_log_analyze);
                        es->verbose = auto_explain_log_verbose;
                        es->buffers = (es->analyze && auto_explain_log_buffers);
+                       es->io = (es->analyze && auto_explain_log_io);
                        es->wal = (es->analyze && auto_explain_log_wal);
                        es->timing = (es->analyze && auto_explain_log_timing);
                        es->summary = es->analyze;
index ee85a67eb2e70d8431e6ae5006da8c9d6ed8c42a..06a8fcc6c5bc3d36bcb42b1c118e1a37f8e8e587 100644 (file)
@@ -128,6 +128,26 @@ LOAD 'auto_explain';
     </listitem>
    </varlistentry>
 
+   <varlistentry id="auto-explain-configuration-parameters-log-io">
+    <term>
+     <varname>auto_explain.log_io</varname> (<type>boolean</type>)
+     <indexterm>
+      <primary><varname>auto_explain.log_io</varname> configuration parameter</primary>
+     </indexterm>
+    </term>
+    <listitem>
+     <para>
+      <varname>auto_explain.log_io</varname> controls whether I/O usage
+      statistics are printed when an execution plan is logged; it's
+      equivalent to the <literal>IO</literal> option of <command>EXPLAIN</command>.
+      This parameter has no effect
+      unless <varname>auto_explain.log_analyze</varname> is enabled.
+      This parameter is off by default.
+      Only superusers can change this setting.
+     </para>
+    </listitem>
+   </varlistentry>
+
    <varlistentry id="auto-explain-configuration-parameters-log-wal">
     <term>
      <varname>auto_explain.log_wal</varname> (<type>boolean</type>)