RE: Newly created replication slot may be invalidated by checkpoint
Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
From: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
To: 'Vitaly Davydov' <v.davydov@postgrespro.ru>
Cc: suyu.cmj <mengjuan.cmj@alibaba-inc.com>, aekorotkov <aekorotkov@gmail.com>, Amit Kapila <amit.kapila16@gmail.com>, tomas <tomas@vondra.me>, michael <michael@paquier.xyz>, bharath.rupireddyforpostgres <bharath.rupireddyforpostgres@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-09-25T05:43:16Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Prevent invalidation of newly synced replication slots.
- 3243c0177efb 17.8 landed
- 919c9fa13cd0 18.2 landed
- 851f6649cc18 19 (unreleased) landed
-
Prevent invalidation of newly created replication slots.
- 3510ebeb0dfa 17.8 landed
- 24cce33c332a 16.12 landed
- aae05622a7cb 15.16 landed
- 7406df60569f 14.21 landed
- d3ceb20846e4 18.2 landed
- 006dd4b2e5b3 19 (unreleased) landed
-
Fix re-distributing previously distributed invalidation messages during logical decoding.
- 45c357e0e85d 17.6 cited
-
Keep WAL segments by the flushed value of the slot's restart LSN
- 2090edc6f32f 17.6 cited
-
Keep WAL segments by slot's last saved restart LSN
- ca307d5cec90 18.0 cited
Dear Vitaly, > I propose to apply this patch and then to think how to resolve this race > condition, which seems to take place in 18 and master as well. No, I think this invalidation can't happen in PG18/HEAD. This is because in CheckpointGuts()->CheckPointReplicationSlots()-> ReplicationSlotsComputeRequiredLSN(), slots are examined one by one to determine whether their restart_lsn has advanced since the last check. If any slot has advanced, protection is applied starting from the oldest restart_lsn. Crucially, this check is performed before WAL removal. The function call was introduced in commit ca307d5cec. Further analysis shows that it is also safe if a slot is being created and WAL advances after CheckpointGuts() but before the removal segments are determined. In this case the restart_lsn points the CHECKPOINT_REDO generated by the current CHECKPOINT. This and later records won't be discarded. Best regards, Hayato Kuroda FUJITSU LIMITED