From: Masahiko Sawada <msawada@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add an xid argument to the logical decoding message callbacks.
Date: Mon, 23 Nov 2026 23:11:04 +0000
Message-ID: <E1xVdBf-000000004jT-3rUl@gemulon.postgresql.org> (raw)
Add an xid argument to the logical decoding message callbacks.
Previously, when streaming an in-progress transaction, a transactional
logical decoding message emitted in a subtransaction was passed to the
stream_message callback with the top-level transaction only, and the
callback had no way to know which subtransaction had emitted it. The
change callbacks get that through ReorderBufferChange, but a message
has none. pgoutput therefore sent the message with the top-level XID,
and when the subtransaction was later rolled back and STREAM ABORT
arrived for it, the subscriber could not discard the message with
it. Oversight in commit 7259736a6e5.
To fix this, we add the XID of the (sub)transaction that emitted the
message as a new argument of both the message and stream_message
callbacks, and have pgoutput send it. Output plugins can now see which
subtransaction a message belongs to, as they already can for the other
change types, while still getting the top-level transaction as
before. Both callbacks get the argument so that a plugin can keep
implementing them with one function, as pgoutput does.
We considered fixing this in a backpatchable way, such as passing the
subtransaction's ReorderBufferTXN to the callback instead of the
top-level one, but that silently changes the meaning of an existing
argument, and an output plugin that keeps its state on the top-level
transaction would break. Adding an argument breaks the ABI, but it is
the cleaner interface, so we chose it and don't backpatch. The bug
exists in the back branches too, but there have been no reports, and
the built-in logical replication doesn't use logical messages there.
Author: Zhijie Hou <houzhijie22@gmail.com>
Co-authored-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/b9b5bd27-6416-48b4-8f73-c5a60e2c97e2@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7bb8cc295b538df21d854e55e12a32dbbd8609b1
Modified Files
--------------
contrib/test_decoding/expected/stream.out | 47 +++++++++++++++++++++++++
contrib/test_decoding/sql/stream.sql | 29 +++++++++++++++
contrib/test_decoding/test_decoding.c | 22 ++++++------
doc/src/sgml/logicaldecoding.sgml | 14 +++++++-
src/backend/replication/logical/logical.c | 12 +++----
src/backend/replication/logical/reorderbuffer.c | 11 +++---
src/backend/replication/pgoutput/pgoutput.c | 17 ++++-----
src/include/replication/output_plugin.h | 10 ++++--
src/include/replication/reorderbuffer.h | 2 ++
9 files changed, 132 insertions(+), 32 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: msawada@postgresql.org
Subject: Re: pgsql: Add an xid argument to the logical decoding message callbacks.
In-Reply-To: <E1xVdBf-000000004jT-3rUl@gemulon.postgresql.org>
References: <E1xVdBf-000000004jT-3rUl@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox