| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | logical: fix recomputation required LSN on restart_lsn-only advancement |
| Date: | 2026-04-21 02:15:55 |
| Message-ID: | D8D9F770-DAA2-482C-A7E0-F87E5104C13E@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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/
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-logical-recompute-required-LSN-when-restart_lsn-a.patch | application/octet-stream | 2.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chao Li | 2026-04-21 02:38:05 | Re: repack: fix a bug to reject deferrable primary key fallback for concurrent mode |
| Previous Message | David Rowley | 2026-04-21 01:40:17 | Re: Add bms_offset_members() function for bitshifting Bitmapsets |