RE: Newly created replication slot may be invalidated by checkpoint
Vitaly Davydov <v.davydov@postgrespro.ru>
From: "Vitaly Davydov" <v.davydov@postgrespro.ru>
To: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>,
"Amit Kapila" <amit.kapila16@gmail.com>
Cc: suyu.cmj <mengjuan.cmj@alibaba-inc.com>, "aekorotkov" <aekorotkov@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-24T14:45:36Z
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
Attachments
- v2-0001-Fix-invalidation-when-slot-is-created-during-checkpo.patch (text/x-patch) patch v2-0001
Dear Amit, Hayato On Wednesday, September 24, 2025 14:31 MSK, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com> wrote: >> I was thinking some more about this solution. Won't it lead to the >> same problem if ReplicationSlotReserveWal() calls >> ReplicationSlotsComputeRequiredLSN() after the above calculation of >> checkpointer? > Exactly. I verified that in your patch, the invalidation can still happen if > we cannot finish the LSN computation before the KeepLogSegments(). Yes. The moment, when WAL reservation takes place is the call of ReplicationSlotsComputeRequiredLSN which updates the oldest slots' lsn (XLogCtl->replicationSlotMinLSN). If it occurs at the moment between KeepLogSeg and RemoveOldXlogFiles, such reservation will not be taken into account. This behaviour seems to be before commit 2090edc6f32f652a2c, but the probability of such race condition was too slow due to the short time period between KeepLogSeg and RemoveOldXlogFiles. The commit 2090edc6f32f652a2c increased the probability of such race condition because CheckPointGuts can take greater time to execute. The attached patch doesn't solve the original problem completely but it decreases the probability of such race condition, as it was before the commit. 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. I updated the patch by improving some comments as suggested by Amit. With best regards, Vitaly