tmp.diffs

application/octet-stream

Filename: tmp.diffs
Type: application/octet-stream
Part: 0
Message: RE: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index c11e588d632..6d342dc40f1 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		updated = false;
 
 	elog(DEBUG1, "performing replication slot checkpoint");
 
@@ -2119,6 +2120,9 @@ CheckPointReplicationSlots(bool is_shutdown)
 			{
 				s->just_dirtied = true;
 				s->dirty = true;
+
+				if (!updated)
+					updated = true;
 			}
 			SpinLockRelease(&s->mutex);
 		}
@@ -2131,7 +2135,8 @@ CheckPointReplicationSlots(bool is_shutdown)
 	 * Recompute the required LSN as SaveSlotToPath() updated
 	 * last_saved_restart_lsn for slots.
 	 */
-	ReplicationSlotsComputeRequiredLSN();
+	if (updated)
+		ReplicationSlotsComputeRequiredLSN();
 }
 
 /*