Hi all, I realized that pg_waldump doesn't show replication origin ID, LSN, and timestamp of PREPARE TRANSACTION record. Commit 7b8a899bdeb improved pg_waldump two years ago so that it reports the detail of information of PREPARE TRANSACTION but ISTM that it overlooked showing replication origin information. As far as I can see in the discussion thread[1], there was no discussion on that. These are helpful when diagnosing 2PC related issues on the subscriber side.
I've attached a patch to add replication origin information to xact_desc_prepare(). Regards, [1] https://www.postgresql.org/message-id/CAHGQGwEvhASad4JJnCv%3D0dW2TJypZgW_Vpb-oZik2a3utCqcrA%40mail.gmail.com -- Masahiko Sawada EDB: https://www.enterprisedb.com/
From b37d5a8cd5b84eeb850bd7ddeb903024652f20d2 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada <sawada.mshk@gmail.com> Date: Mon, 6 Dec 2021 14:32:57 +0900 Subject: [PATCH] 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() report replication origin ID, LSN, and timestamp. --- src/backend/access/rmgrdesc/xactdesc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/access/rmgrdesc/xactdesc.c b/src/backend/access/rmgrdesc/xactdesc.c index 4b0d10f073..ea3649d822 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" @@ -329,7 +330,7 @@ xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec) } 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 +346,12 @@ 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); + + 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 @@ -381,7 +388,8 @@ xact_desc(StringInfo buf, XLogReaderState *record) { 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.24.3 (Apple Git-128)