Checkpoint replication slots later

Ants Aasma <ants.aasma@cybertec.at>

From: Ants Aasma <ants.aasma@cybertec.at>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-05-07T10:28:07Z
Lists: pgsql-hackers

Attachments

Hi,

Right now replication slots are synced close to the beginning of
CheckpointGuts(). Importantly, before CheckPointBuffers() which for spread
checkpoints might take most of checkpoint_timeout to complete. This is a
problem because this function calculates how much WAL to keep around in
ReplicationSlotsComputeRequiredLSN(). By the time RemoveOldXlogFiles() gets
called this information might be quite stale and we hold onto many WAL
files unnecessarily until the next checkpoint cycle.

As far as I could tell there is no reason for this to happen early, so in
the attached patched I just moved it down closer to the end.

Regards,
Ants Aasma