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 <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]> Reviewed-by: João Rito <[email protected]> Reviewed-by: solai v <[email protected]> Discussion: https://postgr.es/m/[email protected] 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(-)
