From 9ec710be86dfac73764f905d494d1375b8979787 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Tue, 2 Jun 2026 14:46:49 +0800
Subject: [PATCH v2 2/2] pg_createsubscriber: Allow duplicate subscription
 names

Subscription names are scoped to individual databases, so the same name can
validly be used for multiple databases.  However, pg_createsubscriber rejected
duplicate --subscription values while parsing command-line options.

Allow duplicate subscription names while continuing to require one
subscription name per specified database.  Adjust the TAP test to exercise the
same subscription name for two databases with distinct replication slot names,
since replication slot names are cluster-wide.

Author: Chao Li <lic@highgo.com>
Reviewed-by:
Discussion: https://postgr.es/m/B08A7C89-B3DE-4C1D-A671-32AD8BAB7E22@gmail.com
---
 src/bin/pg_basebackup/pg_createsubscriber.c        | 9 ++-------
 src/bin/pg_basebackup/t/040_pg_createsubscriber.pl | 8 ++++----
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index 4d705778454..8c06757a971 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -2394,13 +2394,8 @@ main(int argc, char **argv)
 					pg_fatal("replication slot \"%s\" specified more than once for --replication-slot", optarg);
 				break;
 			case 4:
-				if (!simple_string_list_member(&opt.sub_names, optarg))
-				{
-					simple_string_list_append(&opt.sub_names, optarg);
-					num_subs++;
-				}
-				else
-					pg_fatal("subscription \"%s\" specified more than once for --subscription", optarg);
+				simple_string_list_append(&opt.sub_names, optarg);
+				num_subs++;
 				break;
 			case 5:
 				if (!simple_string_list_member(&opt.objecttypes_to_clean, optarg))
diff --git a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
index 9252d1c3c5c..05bb84566ae 100644
--- a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
+++ b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
@@ -334,8 +334,8 @@ is($node_s->safe_psql($db1, "SELECT COUNT(*) FROM pg_publication"),
 
 $node_s->stop;
 
-# dry run mode on node S. Use the same publication name for different
-# databases, since publication names are database-local.
+# dry run mode on node S. Use the same publication and subscription names for
+# different databases, since these names are database-local.
 command_ok(
 	[
 		'pg_createsubscriber',
@@ -348,8 +348,8 @@ command_ok(
 		'--subscriber-port' => $node_s->port,
 		'--publication' => 'same_pub',
 		'--publication' => 'same_pub',
-		'--subscription' => 'sub1',
-		'--subscription' => 'sub2',
+		'--subscription' => 'same_sub',
+		'--subscription' => 'same_sub',
 		'--database' => $db1,
 		'--database' => $db2,
 		'--logdir' => $logdir,
-- 
2.50.1 (Apple Git-155)

