pgsql: Use start LSN for transactional logical decoding messages.

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use start LSN for transactional logical decoding messages.
Date: 2026-11-25 18:31:37
Message-ID: E1xWHmL-00000000Ig8-38T3@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use start LSN for transactional logical decoding messages.

Previously, logical decoding reported the end LSN of the WAL record
for logical messages, whereas other changes in a transaction are
reported with the start LSN of their WAL records. So a transactional
message could get the same LSN as the change following it. A logical
decoding consumer that persists the LSN of the last processed change
to decide where to resume (e.g., the Debezium PostgreSQL connector)
could then skip the following change if it crashed right after
processing the message. While consumers can work around it on their
side, it's better to fix it in core and more consistent with other
changes.

Fix by using the start LSN for transactional
messages. Non-transactional messages keep using the end LSN, since we
assume that each of them is applied and confirmed as a unit of its
own, like a commit; using the start LSN would let the message be
decoded again after a restart.

This changes the LSN that output plugins see for transactional
messages. We don't backpatch it since consumers might have persisted
such LSNs and would have to interpret them differently depending on
the minor version.

Author: Atsushi Torikoshi <torikoshia(at)oss(dot)nttdata(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Reviewed-by: João Rito <joaovictor(dot)rito(at)gmail(dot)com>
Reviewed-by: solai v <solai(dot)cdac(at)gmail(dot)com>
Discussion: https://postgr.es/m/d99c688994ab3a998afe26e61fe4f69f@oss.nttdata.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4255812efdbcf7f1acf6be2211e1b5b11c4d4240

Modified Files
--------------
contrib/test_decoding/expected/messages.out | 25 +++++++++++++++++++++++++
contrib/test_decoding/sql/messages.sql | 17 +++++++++++++++++
doc/src/sgml/logicaldecoding.sgml | 13 +++++++++----
doc/src/sgml/protocol.sgml | 3 ++-
src/backend/replication/logical/decode.c | 14 +++++++++++++-
5 files changed, 66 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2026-11-25 18:54:51 pgsql: doc: Clarify that logical decoding message LSN is the end LSN.
Previous Message Álvaro Herrera 2026-11-25 17:48:44 pgsql: Use indnkeyatts, not indnatts, in infer_collation_opclass_match(