diff options
author | Alexander Korotkov | 2025-06-27 08:49:00 +0000 |
---|---|---|
committer | Alexander Korotkov | 2025-06-27 08:49:00 +0000 |
commit | 7195c804bd12f47a9f1b2df9c2e1794bb04c5987 (patch) | |
tree | bf6ec6d5f940b3883d0e10de95c72a182294d3db | |
parent | 94e2e150ec72a3b37e3847be99c4aca3320c38f9 (diff) |
Fix CheckPointReplicationSlots() with max_replication_slots == 0
ca307d5cec90 made CheckPointReplicationSlots() unconditionally call
ReplicationSlotsComputeRequiredLSN(). It causes an assertion trap when
max_replication_slots equals 0. This commit makes
CheckPointReplicationSlots() call ReplicationSlotsComputeRequiredLSN() only
when at least one slot gets its last_saved_restart_lsn updated. That avoids
an assert trap and also saves some cycles when no one slot has
last_saved_restart_lsn updated.
Based on ideas from Dilip Kumar <[email protected]> and
Hayato Kuroda <[email protected]>.
Reported-by: Zhijie Hou <[email protected]>
Discussion: https://postgr.es/m/OS0PR01MB5716BB506AF934376FF3A8BB947BA%40OS0PR01MB5716.jpnprd01.prod.outlook.com
-rw-r--r-- | src/backend/replication/slot.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index c11e588d632..f9fec50ae88 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -2079,6 +2079,7 @@ void CheckPointReplicationSlots(bool is_shutdown) { int i; + bool last_saved_restart_lsn_updated = false; elog(DEBUG1, "performing replication slot checkpoint"); @@ -2123,15 +2124,23 @@ CheckPointReplicationSlots(bool is_shutdown) SpinLockRelease(&s->mutex); } + /* + * Track if we're going to update slot's last_saved_restart_lsn. We + * need this to know if we need to recompute the required LSN. + */ + if (s->last_saved_restart_lsn != s->data.restart_lsn) + last_saved_restart_lsn_updated = true; + SaveSlotToPath(s, path, LOG); } LWLockRelease(ReplicationSlotAllocationLock); /* - * Recompute the required LSN as SaveSlotToPath() updated - * last_saved_restart_lsn for slots. + * Recompute the required LSN if SaveSlotToPath() updated + * last_saved_restart_lsn for any slot. */ - ReplicationSlotsComputeRequiredLSN(); + if (last_saved_restart_lsn_updated) + ReplicationSlotsComputeRequiredLSN(); } /* |