On Wed, Dec 08, 2021 at 05:03:30PM +0900, Masahiko Sawada wrote: > Agreed. I've attached an updated patch that incorporated your review > comments. Please review it.
That looks correct to me. One thing that I have noticed while reviewing is that we don't check XactCompletionApplyFeedback() in xact_desc_commit(), which would happen if a transaction needs to do a remote_apply on a standby. synchronous_commit is a user-settable parameter, so it seems to me that it could be useful for debugging? That's not related to your patch, but while we are looking at the area.. -- Michael
From c821c67698535ded147e8686c182d91462a16599 Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@paquier.xyz> Date: Thu, 9 Dec 2021 16:00:53 +0900 Subject: [PATCH v3] Make pg_waldump report replication origin ID, LSN, and timestamp. Commit 7b8a899bdeb made pg_waldump report the detail of information about PREPARE TRANSACTION record, like global transaction identifier. However, replication origin LSN and timestamp were not reporeted. These are helpful when diagnosing 2PC-related troubles on the subsciber side. This commit makes xact_desc_prepare() and xact_desc_abort() report replication origin ID, LSN, and timestamp. --- src/backend/access/rmgrdesc/xactdesc.c | 32 ++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/backend/access/rmgrdesc/xactdesc.c b/src/backend/access/rmgrdesc/xactdesc.c index 4b0d10f073..fca03a00d9 100644 --- a/src/backend/access/rmgrdesc/xactdesc.c +++ b/src/backend/access/rmgrdesc/xactdesc.c @@ -16,6 +16,7 @@ #include "access/transam.h" #include "access/xact.h" +#include "replication/origin.h" #include "storage/sinval.h" #include "storage/standbydefs.h" #include "utils/timestamp.h" @@ -299,6 +300,9 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId parsed.tsId, XactCompletionRelcacheInitFileInval(parsed.xinfo)); + if (XactCompletionApplyFeedback(parsed.xinfo)) + appendStringInfoString(buf, "; apply_feedback"); + if (XactCompletionForceSyncCommit(parsed.xinfo)) appendStringInfoString(buf, "; sync"); @@ -312,7 +316,7 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId } static void -xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec) +xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id) { xl_xact_parsed_abort parsed; @@ -326,10 +330,18 @@ xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec) xact_desc_relations(buf, "rels", parsed.nrels, parsed.xnodes); xact_desc_subxacts(buf, parsed.nsubxacts, parsed.subxacts); + + if (parsed.xinfo & XACT_XINFO_HAS_ORIGIN) + { + appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s", + origin_id, + LSN_FORMAT_ARGS(parsed.origin_lsn), + timestamptz_to_str(parsed.origin_timestamp)); + } } static void -xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec) +xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, RepOriginId origin_id) { xl_xact_parsed_prepare parsed; @@ -345,6 +357,16 @@ xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec) standby_desc_invalidations(buf, parsed.nmsgs, parsed.msgs, parsed.dbId, parsed.tsId, xlrec->initfileinval); + + /* + * Check if the replication origin has been set in this record in the + * same way as PrepareRedoAdd(). + */ + if (origin_id != InvalidRepOriginId) + appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s", + origin_id, + LSN_FORMAT_ARGS(parsed.origin_lsn), + timestamptz_to_str(parsed.origin_timestamp)); } static void @@ -375,13 +397,15 @@ xact_desc(StringInfo buf, XLogReaderState *record) { xl_xact_abort *xlrec = (xl_xact_abort *) rec; - xact_desc_abort(buf, XLogRecGetInfo(record), xlrec); + xact_desc_abort(buf, XLogRecGetInfo(record), xlrec, + XLogRecGetOrigin(record)); } else if (info == XLOG_XACT_PREPARE) { xl_xact_prepare *xlrec = (xl_xact_prepare *) rec; - xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec); + xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec, + XLogRecGetOrigin(record)); } else if (info == XLOG_XACT_ASSIGNMENT) { -- 2.34.1
signature.asc
Description: PGP signature