From fcbefaf80e74fbcecfbe09b2c7697bf2a6bc9b83 Mon Sep 17 00:00:00 2001
From: Euler Taveira <euler@eulerto.com>
Date: Wed, 12 Mar 2025 19:50:04 -0300
Subject: [PATCH v5 2/2] max_active_replication_origins defaults to 10

---
 doc/src/sgml/config.sgml                      |  5 ++--
 src/backend/replication/logical/origin.c      | 28 +------------------
 src/backend/utils/misc/guc_tables.c           |  2 +-
 src/backend/utils/misc/postgresql.conf.sample |  3 +-
 4 files changed, 5 insertions(+), 33 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 1ec4aceef4f..4eba6f18036 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5136,9 +5136,8 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
         be created on the server. Setting it to a lower value than the current
         number of tracked replication origins (reflected in
         <link linkend="view-pg-replication-origin-status">pg_replication_origin_status</link>)
-        will prevent the server from starting. It defaults to -1, indicating
-        that the value of <xref linkend="guc-max-replication-slots"/> should be
-        used instead. This parameter can only be set at server start.
+        will prevent the server from starting. It defaults to 10. This parameter
+        can only be set at server start.
 
         <literal>max_active_replication_origins</literal> must be set to at least the
         number of subscriptions that will be added to the subscriber, plus some
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 8252e03f978..6583dd497da 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -101,7 +101,7 @@
 #define PG_REPLORIGIN_CHECKPOINT_TMPFILE PG_REPLORIGIN_CHECKPOINT_FILENAME ".tmp"
 
 /* GUC variables */
-int			max_active_replication_origins = -1;
+int			max_active_replication_origins = 10;
 
 /*
  * Replay progress of a single remote node.
@@ -515,32 +515,6 @@ ReplicationOriginShmemSize(void)
 	if (max_active_replication_origins == 0)
 		return size;
 
-	/*
-	 * Prior to PostgreSQL 18, max_replication_slots was used to set the
-	 * number of replication origins. For backward compatibility, -1 indicates
-	 * to use the fallback value (max_replication_slots).
-	 */
-	if (max_active_replication_origins == -1)
-	{
-		char		buf[32];
-
-		snprintf(buf, sizeof(buf), "%d", max_replication_slots);
-		SetConfigOption("max_active_replication_origins", buf,
-						PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
-
-		/*
-		 * We prefer to report this value's source as PGC_S_DYNAMIC_DEFAULT.
-		 * However, if the DBA explicitly set max_active_replication_origins
-		 * equals to -1 in the config file, then PGC_S_DYNAMIC_DEFAULT will
-		 * fail to override that and we must force the matter with
-		 * PGC_S_OVERRIDE.
-		 */
-		if (max_active_replication_origins == -1)	/* failed to apply it? */
-			SetConfigOption("max_active_replication_origins", buf,
-							PGC_POSTMASTER, PGC_S_OVERRIDE);
-	}
-	Assert(max_active_replication_origins != -1);
-
 	size = add_size(size, offsetof(ReplicationStateCtl, states));
 
 	size = add_size(size,
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index fbaa85c3afd..d891eb34c70 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -3312,7 +3312,7 @@ struct config_int ConfigureNamesInt[] =
 			NULL
 		},
 		&max_active_replication_origins,
-		-1, -1, MAX_BACKENDS,
+		10, 0, MAX_BACKENDS,
 		NULL, NULL, NULL
 	},
 
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index a27840f25c2..fbdd4a8ef26 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -382,8 +382,7 @@
 
 #max_logical_replication_workers = 4	# taken from max_worker_processes
 					# (change requires restart)
-#max_active_replication_origins = -1	# maximum number of active replication origins
-					# -1 to use max_replication_slots
+#max_active_replication_origins = 10	# maximum number of active replication origins
 					# (change requires restart)
 #max_sync_workers_per_subscription = 2	# taken from max_logical_replication_workers
 #max_parallel_apply_workers_per_subscription = 2	# taken from max_logical_replication_workers
-- 
2.39.5

