| From: | Amit Kapila <akapila(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Don't persist synced slots before a consistent snapshot is built |
| Date: | 2026-11-19 03:13:06 |
| Message-ID: | E1xTsa9-00000000KNL-0KTb@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(dot)mshk(at)gmail(dot)com>
Author: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Reviewed-by: João Rito <joaovictor(dot)rito(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAD21AoDdn9QJ2Q5dNkW9dAAzvoH-9yEF7jw64QpHJGqi3YJMvQ@mail.gmail.com
Backpatch-through: 19
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/f66932c8dd42429afb63352cdb6cbc401386a574
Modified Files
--------------
src/backend/replication/logical/slotsync.c | 53 ++++++++++++++++++++----------
1 file changed, 35 insertions(+), 18 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jeff Davis | 2026-11-19 04:04:37 | pgsql: Fix CREATE DATABASE when template0 has ICU rules. |
| Previous Message | Melanie Plageman | 2026-11-18 22:43:33 | pgsql: Recreate read stream across rescans |