From d126399bcd46cf1ecd1a172419bdeaa4f1786fee Mon Sep 17 00:00:00 2001
From: Dilip Kumar <dilipkumarb@google.com>
Date: Tue, 8 Jul 2025 07:00:30 +0000
Subject: [PATCH v1 2/2] Force idle_replication_slot_timeout to 0 during binary
 upgrade

This commit refines handling of idle_replication_slot_timeout during upgrade.
Previously, any value other than 0 would trigger an error during binary
upgrade. Now, the server will automatically force idle_replication_slot_timeout
to 0 if any other value is set.

This also moves the enforcement logic from pg_upgrade into the server itself.
---
 src/backend/replication/slot.c | 11 ++++-------
 src/bin/pg_upgrade/server.c    |  7 -------
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index f369fce2485..b1bc7ad01e4 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -3061,18 +3061,15 @@ WaitForStandbyConfirmation(XLogRecPtr wait_for_lsn)
 /*
  * GUC check_hook for idle_replication_slot_timeout
  *
- * The value of idle_replication_slot_timeout must be set to 0 during
- * a binary upgrade. See start_postmaster() in pg_upgrade for more details.
+ * For binary upgrades, idle_replication_slot_timeout is strictly enforced to
+ * 0. This is crucial to prevent the checkpointer from invalidating replication
+ * slots during the upgrade.  If set otherwise, the value will be forced to 0.
  */
 bool
 check_idle_replication_slot_timeout(int *newval, void **extra, GucSource source)
 {
 	if (IsBinaryUpgrade && *newval != 0)
-	{
-		GUC_check_errdetail("\"%s\" must be set to 0 during binary upgrade mode.",
-							"idle_replication_slot_timeout");
-		return false;
-	}
+		*newval = 0;
 
 	return true;
 }
diff --git a/src/bin/pg_upgrade/server.c b/src/bin/pg_upgrade/server.c
index ce3e989918a..7eb15bc7d5a 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -241,13 +241,6 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error)
 	if (cluster == &new_cluster)
 		appendPQExpBufferStr(&pgoptions, " -c synchronous_commit=off -c fsync=off -c full_page_writes=off");
 
-	/*
-	 * Use idle_replication_slot_timeout=0 to prevent slot invalidation due to
-	 * idle_timeout by checkpointer process during upgrade.
-	 */
-	if (GET_MAJOR_VERSION(cluster->major_version) >= 1800)
-		appendPQExpBufferStr(&pgoptions, " -c idle_replication_slot_timeout=0");
-
 	/*
 	 * Use -b to disable autovacuum and logical replication launcher
 	 * (effective in PG17 or later for the latter).
-- 
2.50.0.727.gbf7dc18ff4-goog

