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: Horiguchi <horikyota.ntt@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: ahsan.hadi <ahsan.hadi@highgo.ca>
Subject: Re: Wrong statistics for size of XLOG_SWITCH during pg_waldump.
Date: Sat, 10 Oct 2020 09:50:02 +0800
Message-ID: <2020101009495929215052@highgo.ca> (raw)
References: <2020100913412132258847@highgo.ca>
	<20201009.174658.2098946247926431018.horikyota.ntt@gmail.com>


>I think that the length of the XLOG_SWITCH record is no other than 24
>bytes. Just adding the padding? garbage bytes to that length doesn't
>seem the right thing to me.
>
>If we want pg_waldump to show that length somewhere, it could be shown
>at the end of that record explicitly:
> 
>rmgr: XLOG        len (rec/tot):     24/16776848, tx:          0, lsn: 0/02000148, prev 0/02000110, desc: SWITCH, trailing-bytes: 16776944

Thanks, I think it's good idea, and new patch attached.

Here's the lookes:
rmgr: XLOG        len (rec/tot):     24/    24, tx:          0, lsn: 0/030000D8, prev 0/03000060, desc: SWITCH, trailing-bytes: 16776936




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_v2.patch (application/octet-stream, 3.6K) download diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index 31e99c2a6d..30159cc820 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,7 +490,7 @@ 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, @@ -472,9 +501,15 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record) id = desc->rm_identify(info); if (id == NULL) - printf("desc: UNKNOWN (%x) ", info & ~XLR_INFO_MASK); + printf("desc: UNKNOWN (%x)", info & ~XLR_INFO_MASK); else - printf("desc: %s ", id); + printf("desc: %s", id); + + if(0 != junk_len) + { + printf(", trailing-bytes: %u", junk_len); + } + printf(" "); initStringInfo(&s); desc->rm_desc(&s, record);

view thread (28+ messages)  latest in thread

Message-ID: <2020101009495929215052@highgo.ca>
Permalink:  ../2020101009495929215052@highgo.ca/
Also on:    postgresql.org/message-id/2020101009495929215052@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, horikyota.ntt@gmail.com, ahsan.hadi@highgo.ca
  Subject: Re: Wrong statistics for size of XLOG_SWITCH during pg_waldump.
  In-Reply-To: <2020101009495929215052@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