Skip to content

Commit c8b733c

Browse files
committed
Improve description of some WAL records with transaction commands
This commit improves the description of some WAL records for the Transaction RMGR: - Track remote_apply for a transaction commit. This GUC is user-settable, so this information can be useful for debugging. - Add replication origin information for PREPARE TRANSACTION, with the origin ID, LSN and timestamp - Same as above, for ROLLBACK PREPARED. This impacts the format of pg_waldump or anything using these description routines, so no backpatch is done. Author: Masahiko Sawada, Michael Paquier Discussion: https://postgr.es/m/CAD21AoD2dJfgsdxk4_KciAZMZQoUiCvmV9sDpp8ZuKLtKCNXaA@mail.gmail.com
1 parent 07eee5a commit c8b733c

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/backend/access/rmgrdesc/xactdesc.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "access/transam.h"
1818
#include "access/xact.h"
19+
#include "replication/origin.h"
1920
#include "storage/sinval.h"
2021
#include "storage/standbydefs.h"
2122
#include "utils/timestamp.h"
@@ -299,6 +300,9 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId
299300
parsed.tsId,
300301
XactCompletionRelcacheInitFileInval(parsed.xinfo));
301302

303+
if (XactCompletionApplyFeedback(parsed.xinfo))
304+
appendStringInfoString(buf, "; apply_feedback");
305+
302306
if (XactCompletionForceSyncCommit(parsed.xinfo))
303307
appendStringInfoString(buf, "; sync");
304308

@@ -312,7 +316,7 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId
312316
}
313317

314318
static void
315-
xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
319+
xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id)
316320
{
317321
xl_xact_parsed_abort parsed;
318322

@@ -326,10 +330,18 @@ xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
326330

327331
xact_desc_relations(buf, "rels", parsed.nrels, parsed.xnodes);
328332
xact_desc_subxacts(buf, parsed.nsubxacts, parsed.subxacts);
333+
334+
if (parsed.xinfo & XACT_XINFO_HAS_ORIGIN)
335+
{
336+
appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s",
337+
origin_id,
338+
LSN_FORMAT_ARGS(parsed.origin_lsn),
339+
timestamptz_to_str(parsed.origin_timestamp));
340+
}
329341
}
330342

331343
static void
332-
xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec)
344+
xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, RepOriginId origin_id)
333345
{
334346
xl_xact_parsed_prepare parsed;
335347

@@ -345,6 +357,16 @@ xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec)
345357

346358
standby_desc_invalidations(buf, parsed.nmsgs, parsed.msgs, parsed.dbId,
347359
parsed.tsId, xlrec->initfileinval);
360+
361+
/*
362+
* Check if the replication origin has been set in this record in the
363+
* same way as PrepareRedoAdd().
364+
*/
365+
if (origin_id != InvalidRepOriginId)
366+
appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s",
367+
origin_id,
368+
LSN_FORMAT_ARGS(parsed.origin_lsn),
369+
timestamptz_to_str(parsed.origin_timestamp));
348370
}
349371

350372
static void
@@ -375,13 +397,15 @@ xact_desc(StringInfo buf, XLogReaderState *record)
375397
{
376398
xl_xact_abort *xlrec = (xl_xact_abort *) rec;
377399

378-
xact_desc_abort(buf, XLogRecGetInfo(record), xlrec);
400+
xact_desc_abort(buf, XLogRecGetInfo(record), xlrec,
401+
XLogRecGetOrigin(record));
379402
}
380403
else if (info == XLOG_XACT_PREPARE)
381404
{
382405
xl_xact_prepare *xlrec = (xl_xact_prepare *) rec;
383406

384-
xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec);
407+
xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec,
408+
XLogRecGetOrigin(record));
385409
}
386410
else if (info == XLOG_XACT_ASSIGNMENT)
387411
{

0 commit comments

Comments
 (0)