From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't persist synced slots before a consistent snapshot is built
Date: Thu, 19 Nov 2026 03:13:06 +0000
Message-ID: <E1xTsa9-00000000KNJ-0GMf@gemulon.postgresql.org> (raw)
Don't persist synced slots before a consistent snapshot is built.
update_local_synced_slot() tries to advance the local slot only when the
remote slot's LSN or catalog_xmin is ahead of it. If no consistent
snapshot can be built from restart_lsn, SS_SKIP_NO_CONSISTENT_SNAPSHOT is
set so the slot stays temporary. But the advance attempt has already moved
the local confirmed_flush to the remote value.
In the next cycle, if the remote slot has not advanced, the advance check
is skipped and the skip reason is reset to SS_SKIP_NONE. Since 788ec96d59,
update_and_persist_local_synced_slot() decides on persistence from
slotsync_skip_reason, so it persists the slot and marks it sync-ready
before a consistent snapshot exists. After promotion, such a slot can
start decoding at a consistent point later than its confirmed_flush,
silently skipping transactions that committed in between and were never
sent to the subscriber. It can also trigger an assertion failure in later
sync cycles.
Fix this by tracking, across update_local_synced_slot(), whether the
current cycle reached a consistent snapshot, and setting
SS_SKIP_NO_CONSISTENT_SNAPSHOT whenever a temporary slot has not reached
one.
Reported-by: Masahiko Sawada <sawada.mshk@gmail.com>
Author: Zhijie Hou <houzhijie22@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: João Rito <joaovictor.rito@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/CAD21AoDdn9QJ2Q5dNkW9dAAzvoH-9yEF7jw64QpHJGqi3YJMvQ@mail.gmail.com
Backpatch-through: 19
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ba11c48390004ed49b889cbd718c9e5f691fe493
Modified Files
--------------
src/backend/replication/logical/slotsync.c | 53 ++++++++++++++++++++----------
1 file changed, 35 insertions(+), 18 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: akapila@postgresql.org
Subject: Re: pgsql: Don't persist synced slots before a consistent snapshot is built
In-Reply-To: <E1xTsa9-00000000KNJ-0GMf@gemulon.postgresql.org>
References: <E1xTsa9-00000000KNJ-0GMf@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