Change the display of WAL usage statistics in Explain.

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
This commit is contained in:
Amit Kapila 2020-05-05 08:00:53 +05:30
parent 5545b69ae6
commit 69bfaf2e1d
11 changed files with 32 additions and 32 deletions

View File

@ -43,7 +43,7 @@ CREATE FUNCTION pg_stat_statements(IN showtext boolean,
OUT blk_read_time float8, OUT blk_read_time float8,
OUT blk_write_time float8, OUT blk_write_time float8,
OUT wal_records int8, OUT wal_records int8,
OUT wal_fpw int8, OUT wal_fpi int8,
OUT wal_bytes numeric OUT wal_bytes numeric
) )
RETURNS SETOF record RETURNS SETOF record

View File

@ -189,7 +189,7 @@ typedef struct Counters
double blk_write_time; /* time spent writing, in msec */ double blk_write_time; /* time spent writing, in msec */
double usage; /* usage factor */ double usage; /* usage factor */
int64 wal_records; /* # of WAL records generated */ 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 */ uint64 wal_bytes; /* total amount of WAL bytes generated */
} Counters; } 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.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
e->counters.usage += USAGE_EXEC(total_time); e->counters.usage += USAGE_EXEC(total_time);
e->counters.wal_records += walusage->wal_records; 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; e->counters.wal_bytes += walusage->wal_bytes;
SpinLockRelease(&e->mutex); SpinLockRelease(&e->mutex);
@ -1824,7 +1824,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
Datum wal_bytes; Datum wal_bytes;
values[i++] = Int64GetDatumFast(tmp.wal_records); 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); snprintf(buf, sizeof buf, UINT64_FORMAT, tmp.wal_bytes);

View File

@ -283,11 +283,11 @@
</row> </row>
<row> <row>
<entry><structfield>wal_fpw</structfield></entry> <entry><structfield>wal_fpi</structfield></entry>
<entry><type>bigint</type></entry> <entry><type>bigint</type></entry>
<entry></entry> <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> </entry>
</row> </row>

View File

@ -198,8 +198,8 @@ ROLLBACK;
<listitem> <listitem>
<para> <para>
Include information on WAL record generation. Specifically, include the Include information on WAL record generation. Specifically, include the
number of records, number of full page writes and amount of WAL bytes number of records, number of full page images (fpi) and amount of WAL
generated. In text format, only non-zero values are printed. This bytes generated. In text format, only non-zero values are printed. This
parameter may only be used when <literal>ANALYZE</literal> is also parameter may only be used when <literal>ANALYZE</literal> is also
enabled. It defaults to <literal>FALSE</literal>. enabled. It defaults to <literal>FALSE</literal>.
</para> </para>

View File

@ -673,10 +673,10 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params,
read_rate, write_rate); read_rate, write_rate);
appendStringInfo(&buf, _("system usage: %s\n"), pg_rusage_show(&ru0)); appendStringInfo(&buf, _("system usage: %s\n"), pg_rusage_show(&ru0));
appendStringInfo(&buf, appendStringInfo(&buf,
_("WAL usage: %ld records, %ld full page writes, " _("WAL usage: %ld records, %ld full page images, "
UINT64_FORMAT " bytes"), UINT64_FORMAT " bytes"),
walusage.wal_records, walusage.wal_records,
walusage.wal_fpw, walusage.wal_fpi,
walusage.wal_bytes); walusage.wal_bytes);
ereport(LOG, ereport(LOG,

View File

@ -998,7 +998,7 @@ XLogRecPtr
XLogInsertRecord(XLogRecData *rdata, XLogInsertRecord(XLogRecData *rdata,
XLogRecPtr fpw_lsn, XLogRecPtr fpw_lsn,
uint8 flags, uint8 flags,
int num_fpw) int num_fpi)
{ {
XLogCtlInsert *Insert = &XLogCtl->Insert; XLogCtlInsert *Insert = &XLogCtl->Insert;
pg_crc32c rdata_crc; pg_crc32c rdata_crc;
@ -1259,7 +1259,7 @@ XLogInsertRecord(XLogRecData *rdata,
{ {
pgWalUsage.wal_bytes += rechdr->xl_tot_len; pgWalUsage.wal_bytes += rechdr->xl_tot_len;
pgWalUsage.wal_records++; pgWalUsage.wal_records++;
pgWalUsage.wal_fpw += num_fpw; pgWalUsage.wal_fpi += num_fpi;
} }
return EndPos; return EndPos;

View File

@ -109,7 +109,7 @@ static MemoryContext xloginsert_cxt;
static XLogRecData *XLogRecordAssemble(RmgrId rmid, uint8 info, static XLogRecData *XLogRecordAssemble(RmgrId rmid, uint8 info,
XLogRecPtr RedoRecPtr, bool doPageWrites, XLogRecPtr RedoRecPtr, bool doPageWrites,
XLogRecPtr *fpw_lsn, int *num_fpw); XLogRecPtr *fpw_lsn, int *num_fpi);
static bool XLogCompressBackupBlock(char *page, uint16 hole_offset, static bool XLogCompressBackupBlock(char *page, uint16 hole_offset,
uint16 hole_length, char *dest, uint16 *dlen); uint16 hole_length, char *dest, uint16 *dlen);
@ -449,7 +449,7 @@ XLogInsert(RmgrId rmid, uint8 info)
bool doPageWrites; bool doPageWrites;
XLogRecPtr fpw_lsn; XLogRecPtr fpw_lsn;
XLogRecData *rdt; XLogRecData *rdt;
int num_fpw = 0; int num_fpi = 0;
/* /*
* Get values needed to decide whether to do full-page writes. Since * Get values needed to decide whether to do full-page writes. Since
@ -459,9 +459,9 @@ XLogInsert(RmgrId rmid, uint8 info)
GetFullPageWriteInfo(&RedoRecPtr, &doPageWrites); GetFullPageWriteInfo(&RedoRecPtr, &doPageWrites);
rdt = XLogRecordAssemble(rmid, info, 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); } while (EndPos == InvalidXLogRecPtr);
XLogResetInsertion(); XLogResetInsertion();
@ -484,7 +484,7 @@ XLogInsert(RmgrId rmid, uint8 info)
static XLogRecData * static XLogRecData *
XLogRecordAssemble(RmgrId rmid, uint8 info, XLogRecordAssemble(RmgrId rmid, uint8 info,
XLogRecPtr RedoRecPtr, bool doPageWrites, XLogRecPtr RedoRecPtr, bool doPageWrites,
XLogRecPtr *fpw_lsn, int *num_fpw) XLogRecPtr *fpw_lsn, int *num_fpi)
{ {
XLogRecData *rdt; XLogRecData *rdt;
uint32 total_len = 0; uint32 total_len = 0;
@ -638,7 +638,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
bkpb.fork_flags |= BKPBLOCK_HAS_IMAGE; bkpb.fork_flags |= BKPBLOCK_HAS_IMAGE;
/* Report a full page image constructed for the WAL record */ /* Report a full page image constructed for the WAL record */
*num_fpw += 1; *num_fpi += 1;
/* /*
* Construct XLogRecData entries for the page content. * Construct XLogRecData entries for the page content.

View File

@ -3343,31 +3343,31 @@ show_wal_usage(ExplainState *es, const WalUsage *usage)
if (es->format == EXPLAIN_FORMAT_TEXT) if (es->format == EXPLAIN_FORMAT_TEXT)
{ {
/* Show only positive counter values. */ /* 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)) (usage->wal_bytes > 0))
{ {
ExplainIndentText(es); ExplainIndentText(es);
appendStringInfoString(es->str, "WAL:"); appendStringInfoString(es->str, "WAL:");
if (usage->wal_records > 0) if (usage->wal_records > 0)
appendStringInfo(es->str, " records=%ld", appendStringInfo(es->str, " records=%ld",
usage->wal_records); usage->wal_records);
if (usage->wal_fpw > 0) if (usage->wal_fpi > 0)
appendStringInfo(es->str, " full page writes=%ld", appendStringInfo(es->str, " fpi=%ld",
usage->wal_fpw); usage->wal_fpi);
if (usage->wal_bytes > 0) if (usage->wal_bytes > 0)
appendStringInfo(es->str, " bytes=" UINT64_FORMAT, appendStringInfo(es->str, " bytes=" UINT64_FORMAT,
usage->wal_bytes); usage->wal_bytes);
appendStringInfoChar(es->str, '\n'); appendStringInfoChar(es->str, '\n');
} }
} }
else else
{ {
ExplainPropertyInteger("WAL records", NULL, ExplainPropertyInteger("WAL Records", NULL,
usage->wal_records, es); usage->wal_records, es);
ExplainPropertyInteger("WAL full page writes", NULL, ExplainPropertyInteger("WAL FPI", NULL,
usage->wal_fpw, es); usage->wal_fpi, es);
ExplainPropertyUInteger("WAL bytes", NULL, ExplainPropertyUInteger("WAL Bytes", NULL,
usage->wal_bytes, es); usage->wal_bytes, es);
} }
} }

View File

@ -248,7 +248,7 @@ WalUsageAdd(WalUsage *dst, WalUsage *add)
{ {
dst->wal_bytes += add->wal_bytes; dst->wal_bytes += add->wal_bytes;
dst->wal_records += add->wal_records; dst->wal_records += add->wal_records;
dst->wal_fpw += add->wal_fpw; dst->wal_fpi += add->wal_fpi;
} }
void 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_bytes += add->wal_bytes - sub->wal_bytes;
dst->wal_records += add->wal_records - sub->wal_records; 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;
} }

View File

@ -280,7 +280,7 @@ struct XLogRecData;
extern XLogRecPtr XLogInsertRecord(struct XLogRecData *rdata, extern XLogRecPtr XLogInsertRecord(struct XLogRecData *rdata,
XLogRecPtr fpw_lsn, XLogRecPtr fpw_lsn,
uint8 flags, uint8 flags,
int num_fpw); int num_fpi);
extern void XLogFlush(XLogRecPtr RecPtr); extern void XLogFlush(XLogRecPtr RecPtr);
extern bool XLogBackgroundFlush(void); extern bool XLogBackgroundFlush(void);
extern bool XLogNeedsFlush(XLogRecPtr RecPtr); extern bool XLogNeedsFlush(XLogRecPtr RecPtr);

View File

@ -35,7 +35,7 @@ typedef struct BufferUsage
typedef struct WalUsage typedef struct WalUsage
{ {
long wal_records; /* # of WAL records produced */ 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 */ uint64 wal_bytes; /* size of WAL records produced */
} WalUsage; } WalUsage;