Keep WAL segments by slot's last saved restart LSN
authorAlexander Korotkov <[email protected]>
Sat, 14 Jun 2025 00:36:04 +0000 (03:36 +0300)
committerAlexander Korotkov <[email protected]>
Sat, 14 Jun 2025 00:36:04 +0000 (03:36 +0300)
commitca307d5cec90a4fde62a50fafc8ab607ff1d8664
tree31b91677cb6a306ecc26352b4cf9c2d1bf9ebdb6
parentc45a1dba0d85c7a44f29f1841afd877ba4f4c683
Keep WAL segments by slot's last saved restart LSN

The patch fixes the issue with the unexpected removal of old WAL segments
after checkpoint, followed by an immediate restart.  The issue occurs when
a slot is advanced after the start of the checkpoint and before old WAL
segments are removed at the end of the checkpoint.

The patch introduces a new in-memory state for slots: last_saved_restart_lsn,
which is used to calculate the oldest LSN for removing WAL segments. This
state is updated every time with the current restart_lsn at the moment when
the slot is saved to disk.

This fix changes the shared memory layout.  It's applied to HEAD only because
we don't have to preserve ABI compatibility during the beta stage.  Another
fix that doesn't affect the ABI is committed to back branches.

Discussion: https://postgr.es/m/1d12d2-67235980-35-19a406a0%4063439497
Author: Vitaly Davydov <[email protected]>
Author: Alexander Korotkov <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
src/backend/replication/slot.c
src/include/replication/slot.h