Change the display of WAL usage statistics in Explain.
authorAmit Kapila <[email protected]>
Tue, 5 May 2020 02:30:53 +0000 (08:00 +0530)
committerAmit Kapila <[email protected]>
Tue, 5 May 2020 02:30:53 +0000 (08:00 +0530)
In commit 33e05f89c5, we have added the option to display WAL usage
statistics in Explain and auto_explain.  The display format used two spaces
between each field which is inconsistent with Buffer usage statistics which
is using one space between each field.  Change the format to make WAL usage
statistics consistent with Buffer usage statistics.

This commit also changed the usage of "full page writes" to
"full page images" for WAL usage statistics to make it consistent with
other parts of code and docs.

Author: Julien Rouhaud, Amit Kapila
Reviewed-by: Justin Pryzby, Kyotaro Horiguchi and Amit Kapila
Discussion: https://postgr.es/m/CAB-hujrP8ZfUkvL5OYETipQwA=e3n7oqHFU=4ZLxWS_Cza3kQQ@mail.gmail.com

contrib/pg_stat_statements/pg_stat_statements--1.7--1.8.sql
contrib/pg_stat_statements/pg_stat_statements.c
doc/src/sgml/pgstatstatements.sgml
doc/src/sgml/ref/explain.sgml
src/backend/access/heap/vacuumlazy.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xloginsert.c
src/backend/commands/explain.c
src/backend/executor/instrument.c
src/include/access/xlog.h
src/include/executor/instrument.h

index d0a6c3b4fc8ac74de37cd4f355014bfee4527ea4..0f63f08f7ebcb308fa21b69af5248bc78c1c45f0 100644 (file)
@@ -43,7 +43,7 @@ CREATE FUNCTION pg_stat_statements(IN showtext boolean,
     OUT blk_read_time float8,
     OUT blk_write_time float8,
     OUT wal_records int8,
-    OUT wal_fpw int8,
+    OUT wal_fpi int8,
     OUT wal_bytes numeric
 )
 RETURNS SETOF record
index 90bc6fd013515e8ba3f6b2a8408350e1638059b5..4ce25fb88aaa20daaeae6f39f289c6087ba28986 100644 (file)
@@ -189,7 +189,7 @@ typedef struct Counters
        double          blk_write_time; /* time spent writing, in msec */
        double          usage;                  /* usage factor */
        int64           wal_records;    /* # of WAL records generated */
-       int64           wal_fpw;        /* # of WAL full page writes generated */
+       int64           wal_fpi;                /* # of WAL full page images generated */
        uint64          wal_bytes;              /* total amount of WAL bytes generated */
 } Counters;
 
@@ -1432,7 +1432,7 @@ pgss_store(const char *query, uint64 queryId,
                e->counters.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
                e->counters.usage += USAGE_EXEC(total_time);
                e->counters.wal_records += walusage->wal_records;
-               e->counters.wal_fpw += walusage->wal_fpw;
+               e->counters.wal_fpi += walusage->wal_fpi;
                e->counters.wal_bytes += walusage->wal_bytes;
 
                SpinLockRelease(&e->mutex);
@@ -1824,7 +1824,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
                        Datum           wal_bytes;
 
                        values[i++] = Int64GetDatumFast(tmp.wal_records);
-                       values[i++] = Int64GetDatumFast(tmp.wal_fpw);
+                       values[i++] = Int64GetDatumFast(tmp.wal_fpi);
 
                        snprintf(buf, sizeof buf, UINT64_FORMAT, tmp.wal_bytes);
 
index 2120fb4c3f64441b04eb2c05829850ee9925e274..b1d5f3d1dcb3053c01ce67c11fd4b039c3cf09a9 100644 (file)
      </row>
 
      <row>
-      <entry><structfield>wal_fpw</structfield></entry>
+      <entry><structfield>wal_fpi</structfield></entry>
       <entry><type>bigint</type></entry>
       <entry></entry>
       <entry>
-        Total number of WAL full page writes generated by the statement
+        Total number of WAL full page images generated by the statement
       </entry>
      </row>
 
index aedd70a6ad201a42f4498c4fffa2b167403bd2a6..c6f333c3c9049b0a0eb99b2efb3798851be84138 100644 (file)
@@ -198,8 +198,8 @@ ROLLBACK;
     <listitem>
      <para>
       Include information on WAL record generation. Specifically, include the
-      number of records, number of full page writes and amount of WAL bytes
-      generated.  In text format, only non-zero values are printed.  This
+      number of records, number of full page images (fpi) and amount of WAL
+      bytes generated.  In text format, only non-zero values are printed.  This
       parameter may only be used when <literal>ANALYZE</literal> is also
       enabled.  It defaults to <literal>FALSE</literal>.
      </para>
index 3c18db29f138389d09091618f6d66af3b140e425..3bef0e124bac2f524aab44697586f4ec28b62615 100644 (file)
@@ -673,10 +673,10 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params,
                                                         read_rate, write_rate);
                        appendStringInfo(&buf, _("system usage: %s\n"), pg_rusage_show(&ru0));
                        appendStringInfo(&buf,
-                                                        _("WAL usage: %ld records, %ld full page writes, "
+                                                        _("WAL usage: %ld records, %ld full page images, "
                                                           UINT64_FORMAT " bytes"),
                                                         walusage.wal_records,
-                                                        walusage.wal_fpw,
+                                                        walusage.wal_fpi,
                                                         walusage.wal_bytes);
 
                        ereport(LOG,
index 065eb275b1cae4aeeae158e2c0905ab59201f8fa..0d3d670928430e7972e2c37ac3fe0a689b8b1bbe 100644 (file)
@@ -998,7 +998,7 @@ XLogRecPtr
 XLogInsertRecord(XLogRecData *rdata,
                                 XLogRecPtr fpw_lsn,
                                 uint8 flags,
-                                int num_fpw)
+                                int num_fpi)
 {
        XLogCtlInsert *Insert = &XLogCtl->Insert;
        pg_crc32c       rdata_crc;
@@ -1259,7 +1259,7 @@ XLogInsertRecord(XLogRecData *rdata,
        {
                pgWalUsage.wal_bytes += rechdr->xl_tot_len;
                pgWalUsage.wal_records++;
-               pgWalUsage.wal_fpw += num_fpw;
+               pgWalUsage.wal_fpi += num_fpi;
        }
 
        return EndPos;
index 4259309dbae5961525eda348bf199a1af865b79a..b21679f09eb458a36e6552cfb4fd72f0d519a4f0 100644 (file)
@@ -109,7 +109,7 @@ static MemoryContext xloginsert_cxt;
 
 static XLogRecData *XLogRecordAssemble(RmgrId rmid, uint8 info,
                                                                           XLogRecPtr RedoRecPtr, bool doPageWrites,
-                                                                          XLogRecPtr *fpw_lsn, int *num_fpw);
+                                                                          XLogRecPtr *fpw_lsn, int *num_fpi);
 static bool XLogCompressBackupBlock(char *page, uint16 hole_offset,
                                                                        uint16 hole_length, char *dest, uint16 *dlen);
 
@@ -449,7 +449,7 @@ XLogInsert(RmgrId rmid, uint8 info)
                bool            doPageWrites;
                XLogRecPtr      fpw_lsn;
                XLogRecData *rdt;
-               int                     num_fpw = 0;
+               int                     num_fpi = 0;
 
                /*
                 * Get values needed to decide whether to do full-page writes. Since
@@ -459,9 +459,9 @@ XLogInsert(RmgrId rmid, uint8 info)
                GetFullPageWriteInfo(&RedoRecPtr, &doPageWrites);
 
                rdt = XLogRecordAssemble(rmid, info, RedoRecPtr, doPageWrites,
-                                                                &fpw_lsn, &num_fpw);
+                                                                &fpw_lsn, &num_fpi);
 
-               EndPos = XLogInsertRecord(rdt, fpw_lsn, curinsert_flags, num_fpw);
+               EndPos = XLogInsertRecord(rdt, fpw_lsn, curinsert_flags, num_fpi);
        } while (EndPos == InvalidXLogRecPtr);
 
        XLogResetInsertion();
@@ -484,7 +484,7 @@ XLogInsert(RmgrId rmid, uint8 info)
 static XLogRecData *
 XLogRecordAssemble(RmgrId rmid, uint8 info,
                                   XLogRecPtr RedoRecPtr, bool doPageWrites,
-                                  XLogRecPtr *fpw_lsn, int *num_fpw)
+                                  XLogRecPtr *fpw_lsn, int *num_fpi)
 {
        XLogRecData *rdt;
        uint32          total_len = 0;
@@ -638,7 +638,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
                        bkpb.fork_flags |= BKPBLOCK_HAS_IMAGE;
 
                        /* Report a full page image constructed for the WAL record */
-                       *num_fpw += 1;
+                       *num_fpi += 1;
 
                        /*
                         * Construct XLogRecData entries for the page content.
index 7ae613167601729f62fb80c942291b8d9efe5470..1275bec673209589b983ab884c44b30f7faaa5aa 100644 (file)
@@ -3343,31 +3343,31 @@ show_wal_usage(ExplainState *es, const WalUsage *usage)
        if (es->format == EXPLAIN_FORMAT_TEXT)
        {
                /* Show only positive counter values. */
-               if ((usage->wal_records > 0) || (usage->wal_fpw > 0) ||
+               if ((usage->wal_records > 0) || (usage->wal_fpi > 0) ||
                        (usage->wal_bytes > 0))
                {
                        ExplainIndentText(es);
                        appendStringInfoString(es->str, "WAL:");
 
                        if (usage->wal_records > 0)
-                               appendStringInfo(es->str, "  records=%ld",
+                               appendStringInfo(es->str, " records=%ld",
                                                                 usage->wal_records);
-                       if (usage->wal_fpw > 0)
-                               appendStringInfo(es->str, "  full page writes=%ld",
-                                                                usage->wal_fpw);
+                       if (usage->wal_fpi > 0)
+                               appendStringInfo(es->str, " fpi=%ld",
+                                                                usage->wal_fpi);
                        if (usage->wal_bytes > 0)
-                               appendStringInfo(es->str, "  bytes=" UINT64_FORMAT,
+                               appendStringInfo(es->str, " bytes=" UINT64_FORMAT,
                                                                 usage->wal_bytes);
                        appendStringInfoChar(es->str, '\n');
                }
        }
        else
        {
-               ExplainPropertyInteger("WAL records", NULL,
+               ExplainPropertyInteger("WAL Records", NULL,
                                                           usage->wal_records, es);
-               ExplainPropertyInteger("WAL full page writes", NULL,
-                                                          usage->wal_fpw, es);
-               ExplainPropertyUInteger("WAL bytes", NULL,
+               ExplainPropertyInteger("WAL FPI", NULL,
+                                                          usage->wal_fpi, es);
+               ExplainPropertyUInteger("WAL Bytes", NULL,
                                                                usage->wal_bytes, es);
        }
 }
index 7c9d7235526d9215e9f7d76dd31a85d7b671ad74..fbedb5aaf600277af0d85996a6f00250ebf798b5 100644 (file)
@@ -248,7 +248,7 @@ WalUsageAdd(WalUsage *dst, WalUsage *add)
 {
        dst->wal_bytes += add->wal_bytes;
        dst->wal_records += add->wal_records;
-       dst->wal_fpw += add->wal_fpw;
+       dst->wal_fpi += add->wal_fpi;
 }
 
 void
@@ -256,5 +256,5 @@ WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
 {
        dst->wal_bytes += add->wal_bytes - sub->wal_bytes;
        dst->wal_records += add->wal_records - sub->wal_records;
-       dst->wal_fpw += add->wal_fpw - sub->wal_fpw;
+       dst->wal_fpi += add->wal_fpi - sub->wal_fpi;
 }
index 0a12afb59e6e75c7c2dd12db2547beae8e452211..e917dfe92d84e3300659a73891a459292f374ffb 100644 (file)
@@ -280,7 +280,7 @@ struct XLogRecData;
 extern XLogRecPtr XLogInsertRecord(struct XLogRecData *rdata,
                                                                   XLogRecPtr fpw_lsn,
                                                                   uint8 flags,
-                                                                  int num_fpw);
+                                                                  int num_fpi);
 extern void XLogFlush(XLogRecPtr RecPtr);
 extern bool XLogBackgroundFlush(void);
 extern bool XLogNeedsFlush(XLogRecPtr RecPtr);
index 50d672b270db0c4fb17b51fc5fc8676b4ab10b59..a97562e7a4fea3bfeb04d81301744bb699a1558b 100644 (file)
@@ -35,7 +35,7 @@ typedef struct BufferUsage
 typedef struct WalUsage
 {
        long            wal_records;    /* # of WAL records produced */
-       long            wal_fpw;        /* # of WAL full page writes produced */
+       long            wal_fpi;                /* # of WAL full page images produced */
        uint64          wal_bytes;              /* size of WAL records produced */
 } WalUsage;