Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHhiU-0001Pg-9S for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Jun 2017 02:26:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dHhiT-0004oF-Qv for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Jun 2017 02:26:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dHhhm-0003Zo-Ms for pgsql-bugs@postgresql.org; Mon, 05 Jun 2017 02:25:18 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dHhhi-00026y-Tv for pgsql-bugs@postgresql.org; Mon, 05 Jun 2017 02:25:18 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 8ADD720A5F; Sun, 4 Jun 2017 22:25:13 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Sun, 04 Jun 2017 22:25:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=ew5HGKipZeKFhpUkFR RGPJo9Ohjc1oAAb3qb8tr59yU=; b=BACBdnlw0Etec8FICGN+wP1ammVrWgM7Wb n7E5uQ0s4vW+sMs1bj5wMgy9d40eII+i9+OVHHKV6ZhvVSf8j+hPzdmfO4l2iJju fEYuKiopW3BFhpGDt/0Debb+qnP6yjr4l2Y2p7/svy8zo9XAi5xONi6eC1kLWHxb PL6sxwSDmjLIKxTtTPKfZhDOxa9nb4f2RfJDfsFurUJOsO+JEuLegs9dcON6LEbC CtZfy1uPBi+bwumzLnMi8F0S+K/72/DdQif8CB6Sog8dAXI0i/c0dcjj2JulPDyk JIFT+l8xESieuoqvwIOdcz/GW1oarQlWud+Oj1oQ+pkzYrRR1G0g== X-ME-Sender: X-Sasl-enc: CbmkeoWKXK6m2sfhF3on8dgHfXgzWck81bQsp/6+yh/J 1496629513 Received: from intern.anarazel.de (unknown [172.58.38.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 09BEB7E5F1; Sun, 4 Jun 2017 22:25:13 -0400 (EDT) Date: Sun, 4 Jun 2017 19:25:11 -0700 From: Andres Freund To: Heikki Linnakangas Cc: pgsql-bugs@postgresql.org, chjischj@163.com Subject: Re: BUG #14687: pg_xlogdump does only count "main data" for record length and leading to incorrect statistics Message-ID: <20170605022511.imow2t2ojsbauk72@alap3.anarazel.de> References: <20170603165939.1436.58887@wrigleys.postgresql.org> <20170604231012.rkhlpf5hqiiszwmb@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="s7h4lh7oaiz2itqc" Content-Disposition: inline In-Reply-To: <20170604231012.rkhlpf5hqiiszwmb@alap3.anarazel.de> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --s7h4lh7oaiz2itqc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Heikki, On 2017-06-04 16:10:12 -0700, Andres Freund wrote: > On 2017-06-03 16:59:39 +0000, chjischj@163.com wrote: > > Currently, record length in pg_xlogdump/pg_waldump's output only count > > length of "main data", > > Good catch! Will fix. I notice that this seems to originate in https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=ebc2b681b8ffa597137aa7a19619e6a21176e928 https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=2c03216d831160bedd72d45f712601b6f7d03f1c and that it's not just stats, but also plain xlogdump displaying wrong data. Do you see any better way to get at the !fpi len than to iterate over the blocks and sum up the image length? It's not really accurate to display len (rec/tot) as total-fpi, total, but I don't have a better backward-compatible idea? Actually, I don't even have a better idea for master, so maybe it's ok as proposed? - Andres --s7h4lh7oaiz2itqc Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="waldump.diff" diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index 6bc27f4be3..1fcce53379 100644 --- a/src/bin/pg_waldump/pg_waldump.c +++ b/src/bin/pg_waldump/pg_waldump.c @@ -363,6 +363,37 @@ XLogDumpReadPage(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) +{ + int block_id; + + /* + * Calculate the amount of FPI data in the record. + * + * XXX: We peek into xlogreader's private decoded backup blocks for the + * bimg_len indicating the length of FPI data. It doesn't seem worth it to + * add an accessor macro for this. + */ + *fpi_len = 0; + for (block_id = 0; block_id <= record->max_block_id; block_id++) + { + if (XLogRecHasBlockImage(record, block_id)) + *fpi_len += record->blocks[block_id].bimg_len; + } + + /* + * Calculate the length of the record as the total length - the length of + * all the block images. That's commonly more accurate than just using + * XLogRecGetDataLen(), because that's only the main record, not per-block + * data registered wity XLogRegisterBufData(). + */ + *rec_len = XLogRecGetTotalLen(record) - *fpi_len; +} + +/* * Store per-rmgr and per-record statistics for a given record. */ static void @@ -373,26 +404,12 @@ XLogDumpCountRecord(XLogDumpConfig *config, XLogDumpStats *stats, uint8 recid; uint32 rec_len; uint32 fpi_len; - int block_id; stats->count++; rmid = XLogRecGetRmid(record); - rec_len = XLogRecGetDataLen(record) + SizeOfXLogRecord; - /* - * Calculate the amount of FPI data in the record. - * - * XXX: We peek into xlogreader's private decoded backup blocks for the - * bimg_len indicating the length of FPI data. It doesn't seem worth it to - * add an accessor macro for this. - */ - fpi_len = 0; - for (block_id = 0; block_id <= record->max_block_id; block_id++) - { - if (XLogRecHasBlockImage(record, block_id)) - fpi_len += record->blocks[block_id].bimg_len; - } + XLogDumpRecordLen(record, &rec_len, &fpi_len); /* Update per-rmgr statistics */ @@ -422,6 +439,8 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record) { const char *id; const RmgrDescData *desc = &RmgrDescTable[XLogRecGetRmid(record)]; + uint32 rec_len; + uint32 fpi_len; RelFileNode rnode; ForkNumber forknum; BlockNumber blk; @@ -429,13 +448,15 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record) uint8 info = XLogRecGetInfo(record); XLogRecPtr xl_prev = XLogRecGetPrev(record); + XLogDumpRecordLen(record, &rec_len, &fpi_len); + id = desc->rm_identify(info); if (id == NULL) id = psprintf("UNKNOWN (%x)", info & ~XLR_INFO_MASK); printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, lsn: %X/%08X, prev %X/%08X, ", desc->rm_name, - XLogRecGetDataLen(record), XLogRecGetTotalLen(record), + rec_len, XLogRecGetTotalLen(record), XLogRecGetXid(record), (uint32) (record->ReadRecPtr >> 32), (uint32) record->ReadRecPtr, (uint32) (xl_prev >> 32), (uint32) xl_prev); --s7h4lh7oaiz2itqc Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --s7h4lh7oaiz2itqc--