pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: movead.li@highgo.ca <movead.li@highgo.ca>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: ahsan.hadi <ahsan.hadi@highgo.ca>
Subject: Wrong statistics for size of XLOG_SWITCH during pg_waldump.
Date: Fri, 9 Oct 2020 13:41:25 +0800
Message-ID: <2020100913412132258847@highgo.ca> (raw)

Hello hackers,

We know that pg_waldump can statistics size for every kind of records. When I use
the feature I find it misses some size for XLOG_SWITCH records. When a user does
a pg_wal_switch(), then postgres will discard the remaining size in the current wal
segment, and the pg_waldump tool misses the discard size.

I think it will be better if pg_waldump  can show the matter, so I make a patch
which regards the discard size as a part of XLOG_SWITCH record, it works if we
want to display the detail of wal records or the statistics, and patch attached.

What's your opinion?



Regards,
Highgo Software (Canada/China/Pakistan) 
URL : www.highgo.ca 
EMAIL: mailto:movead(dot)li(at)highgo(dot)ca


Attachments:

fix_waldump_size_for_wal_switch.patch (application/octet-stream, 3.3K) download diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index 31e99c2a6d..011606ecf2 100644 --- a/src/bin/pg_waldump/pg_waldump.c +++ b/src/bin/pg_waldump/pg_waldump.c @@ -24,6 +24,7 @@ #include "common/logging.h" #include "getopt_long.h" #include "rmgrdesc.h" +#include "catalog/pg_control.h" static const char *progname; @@ -380,9 +381,11 @@ WALDumpReadPage(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, * Calculate the size of a record, split into !FPI and FPI parts. */ static void -XLogDumpRecordLen(XLogReaderState *record, uint32 *rec_len, uint32 *fpi_len) +XLogDumpRecordLen(XLogReaderState *record, uint32 *rec_len, uint32 *fpi_len, uint32 *junk_len) { int block_id; + RmgrId rmid; + uint8 info; /* * Calculate the amount of FPI data in the record. @@ -403,6 +406,31 @@ XLogDumpRecordLen(XLogReaderState *record, uint32 *rec_len, uint32 *fpi_len) * all the block images. */ *rec_len = XLogRecGetTotalLen(record) - *fpi_len; + + rmid = XLogRecGetRmid(record); + info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; + + /* + * If it's a wal switch record, we should caculate the junk size which skipped + * by this record. + */ + *junk_len = 0; + if(RM_XLOG_ID == rmid && XLOG_SWITCH == info) + { + XLogSegNo startSegNo; + XLogSegNo endSegNo; + + XLByteToSeg(record->ReadRecPtr, startSegNo, record->segcxt.ws_segsize); + XLByteToSeg(record->EndRecPtr, endSegNo, record->segcxt.ws_segsize); + + *junk_len = record->EndRecPtr - record->ReadRecPtr - XLogRecGetTotalLen(record); + /* + * If the wal switch record spread on two segments, we should extra minus the + * long page head. + */ + if(startSegNo != endSegNo) + *junk_len -= SizeOfXLogLongPHD; + } } /* @@ -416,12 +444,14 @@ XLogDumpCountRecord(XLogDumpConfig *config, XLogDumpStats *stats, uint8 recid; uint32 rec_len; uint32 fpi_len; + uint32 junk_len; stats->count++; rmid = XLogRecGetRmid(record); - XLogDumpRecordLen(record, &rec_len, &fpi_len); + XLogDumpRecordLen(record, &rec_len, &fpi_len, &junk_len); + rec_len += junk_len; /* Update per-rmgr statistics */ @@ -435,9 +465,7 @@ XLogDumpCountRecord(XLogDumpConfig *config, XLogDumpStats *stats, * are the rmgr's domain (resulting in sixteen possible entries per * RmgrId). */ - recid = XLogRecGetInfo(record) >> 4; - stats->record_stats[rmid][recid].count++; stats->record_stats[rmid][recid].rec_len += rec_len; stats->record_stats[rmid][recid].fpi_len += fpi_len; @@ -453,6 +481,7 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record) const RmgrDescData *desc = &RmgrDescTable[XLogRecGetRmid(record)]; uint32 rec_len; uint32 fpi_len; + uint32 junk_len; RelFileNode rnode; ForkNumber forknum; BlockNumber blk; @@ -461,11 +490,11 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record) XLogRecPtr xl_prev = XLogRecGetPrev(record); StringInfoData s; - XLogDumpRecordLen(record, &rec_len, &fpi_len); + XLogDumpRecordLen(record, &rec_len, &fpi_len, &junk_len); printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, lsn: %X/%08X, prev %X/%08X, ", desc->rm_name, - rec_len, XLogRecGetTotalLen(record), + rec_len, XLogRecGetTotalLen(record) + junk_len, XLogRecGetXid(record), (uint32) (record->ReadRecPtr >> 32), (uint32) record->ReadRecPtr, (uint32) (xl_prev >> 32), (uint32) xl_prev);

view thread (28+ messages)  latest in thread

Message-ID: <2020100913412132258847@highgo.ca>
Permalink:  ../2020100913412132258847@highgo.ca/
Also on:    postgresql.org/message-id/2020100913412132258847@highgo.ca

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: movead.li@highgo.ca, ahsan.hadi@highgo.ca
  Subject: Re: Wrong statistics for size of XLOG_SWITCH during pg_waldump.
  In-Reply-To: <2020100913412132258847@highgo.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox