From 8600d480de304ffe4c6a313b6fba1e411ab2e706 Mon Sep 17 00:00:00 2001 From: Euler Taveira Date: Sun, 26 Jul 2020 16:01:52 -0300 Subject: [PATCH] Fix an oversight in format 2: nextlsn Format 2 (1b0cbac484f4fe5db80445f6721957511b4de7b7) forgot to add nextlsn. Format 1 includes this information if include-lsn is provided. This information can be useful for applications that use LSN position as a restart point. --- wal2json.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wal2json.c b/wal2json.c index c3465a4..d90fd79 100644 --- a/wal2json.c +++ b/wal2json.c @@ -853,6 +853,10 @@ pg_decode_begin_txn_v2(LogicalDecodingContext *ctx, ReorderBufferTXN *txn) char *lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, UInt64GetDatum(txn->final_lsn))); appendStringInfo(ctx->out, ",\"lsn\":\"%s\"", lsn_str); pfree(lsn_str); + + lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, UInt64GetDatum(txn->end_lsn))); + appendStringInfo(ctx->out, ",\"nextlsn\":\"%s\"", lsn_str); + pfree(lsn_str); } appendStringInfoChar(ctx->out, '}'); @@ -931,6 +935,10 @@ pg_decode_commit_txn_v2(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, char *lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, UInt64GetDatum(commit_lsn))); appendStringInfo(ctx->out, ",\"lsn\":\"%s\"", lsn_str); pfree(lsn_str); + + lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, UInt64GetDatum(txn->end_lsn))); + appendStringInfo(ctx->out, ",\"nextlsn\":\"%s\"", lsn_str); + pfree(lsn_str); } appendStringInfoChar(ctx->out, '}');