Re: logical: fix recomputation required LSN on restart_lsn-only advancement - Mailing list pgsql-hackers

From Hu Xunqi
Subject Re: logical: fix recomputation required LSN on restart_lsn-only advancement
Date
Msg-id CAE4_qQa7ZE-kMo8JkxxDrtxGgwWEpx1QjGKtcrY9dDia15pGZg@mail.gmail.com
Whole thread
In response to logical: fix recomputation required LSN on restart_lsn-only advancement  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers
On Tue, Apr 21, 2026 at 10:16 AM Chao Li <li.evan.chao@gmail.com> wrote:
Hi,

While reading logical replication code, I found an issue in LogicalConfirmReceivedLocation().

In LogicalConfirmReceivedLocation(), updated_restart is tracked independently from updated_xmin, and the slot is marked dirty and saved when either one changed. But after that, ReplicationSlotsComputeRequiredLSN() is still only called inside "if (updated_xmin)”.

So for the restart-only case:

* updated_restart = true
* updated_xmin = false
* ReplicationSlotSave() runs
* ReplicationSlotsComputeRequiredLSN() does not run because updated_xmin is false

That means the global retention point managed by XLogSetReplicationSlotMinimumLSN() can stay stale until some later unrelated event recomputes it. Since ReplicationSlotsComputeRequiredLSN() derives the global minimum from slot restat_lsn, skipping it after a restart-only advance can retain excess WAL and may lead to WAL bloat.

This patch fixes the problem by moving ReplicationSlotsComputeRequiredLSN() under “if (updated_restart)”.

Looks like this issue has been there for a long time, so if this analysis is correct, it may also be worth back-patching.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

 
I think this change is reasonable.
This makes the recomputation condition match the state it actually depends on.

Regards,
Xunqi Hu

pgsql-hackers by date:

Previous
From: Ayush Tiwari
Date:
Subject: Re: [PATCH] postmaster: fix stale PM_STARTUP comment
Next
From: Ashutosh Bapat
Date:
Subject: Re: [Bug][patch]: After dropping the last label from a property graph element, invoking pg_get_propgraphdef() triggers an assertion failure