Skip to content

Commit

Permalink
Added start_lsn and end_lsn
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan committed Mar 31, 2015
1 parent 1b35f46 commit bdd4d0e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions wal2json.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ pg_decode_begin_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
if (data->include_xids)
appendStringInfo(ctx->out, "\t\"xid\": %u,\n", txn->xid);

if (data->include_lsn) {
char *lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, ctx->write_location));
appendStringInfo(ctx->out, "\t\"start_lsn\": \"%s\",", lsn_str);
pfree(lsn_str);
}

if (data->include_timestamp)
appendStringInfo(ctx->out, "\t\"timestamp\": \"%s\",\n", timestamptz_to_str(txn->commit_time));

Expand All @@ -236,13 +242,14 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
/* Transaction ends */
OutputPluginPrepareWrite(ctx, true);

appendStringInfoString(ctx->out, "\t],\n");
// TODO: what if not, bad commas...
appendStringInfoString(ctx->out, "\t]");
if (data->include_lsn) {
char *lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, commit_lsn));
appendStringInfo(ctx->out, "\t\"lsn\": \"%s\"\n", lsn_str);
appendStringInfo(ctx->out, ",\n\t\"end_lsn\": \"%s\"", lsn_str);
pfree(lsn_str);
}
appendStringInfoString(ctx->out, "}");
appendStringInfoString(ctx->out, "\n}");

OutputPluginWrite(ctx, true);
}
Expand Down

0 comments on commit bdd4d0e

Please sign in to comment.