v1-0001-logical-recompute-required-LSN-when-restart_lsn-a.patch
application/octet-stream
Filename: v1-0001-logical-recompute-required-LSN-when-restart_lsn-a.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0001
Subject: logical: recompute required LSN when restart_lsn advances
| File | + | − |
|---|---|---|
| src/backend/replication/logical/logical.c | 11 | 5 |
From 643c0ff596153fe8c348ed892eb3db7017225a40 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Tue, 21 Apr 2026 09:53:59 +0800
Subject: [PATCH v1] logical: recompute required LSN when restart_lsn advances
LogicalConfirmReceivedLocation() saves slot state when either
catalog_xmin or restart_lsn is updated, but it only recomputes the
global WAL retention requirement in the updated_xmin path.
This misses the restart_lsn-only case, so excess WAL can be retained
until a later recomputation.
Call ReplicationSlotsComputeRequiredLSN() when updated_restart is true,
and clarify the nearby comments.
Author: Chao Li <lic@highgo.com>
Reviewed-by:
Discussion: https://postgr.es/m/
---
src/backend/replication/logical/logical.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index a33a685dcc6..913a2a94136 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -1901,10 +1901,10 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
}
/*
- * Now the new xmin is safely on disk, we can let the global value
- * advance. We do not take ProcArrayLock or similar since we only
- * advance xmin here and there's not much harm done by a concurrent
- * computation missing that.
+ * Now the new xmin is safely on disk, we can let the global xmin
+ * horizon advance. We do not take ProcArrayLock or similar since we
+ * only advance xmin here and there's not much harm done by a
+ * concurrent computation missing that.
*/
if (updated_xmin)
{
@@ -1913,8 +1913,14 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
SpinLockRelease(&MyReplicationSlot->mutex);
ReplicationSlotsComputeRequiredXmin(false);
- ReplicationSlotsComputeRequiredLSN();
}
+
+ /*
+ * Now the new restart_lsn is safely on disk, recompute the global
+ * WAL retention requirement.
+ */
+ if (updated_restart)
+ ReplicationSlotsComputeRequiredLSN();
}
else
{
--
2.50.1 (Apple Git-155)