From 800b010992453e5e82a929b41a091caa6b63e175 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Mon, 1 Jun 2026 20:52:35 +0800 Subject: [PATCH v3] pg_createsubscriber: allow duplicate publication names Publication names are scoped to individual databases, so the same name can validly be used for multiple databases. However, pg_createsubscriber rejected duplicate --publication values while parsing command-line options. Allow duplicate publication names while continuing to require one publication name per specified database. Adjust the TAP test to exercise the same publication name for two databases. Do not make a similar change for subscription names. If --replication-slot is omitted, pg_createsubscriber uses the subscription name as the replication slot name, and replication slot names are cluster-wide. Author: Chao Li Reviewed-by: Shlok Kyal Reviewed-by: Amit Kapila Reviewed-by: Hayato Kuroda Discussion: https://postgr.es/m/B08A7C89-B3DE-4C1D-A671-32AD8BAB7E22@gmail.com --- src/bin/pg_basebackup/pg_createsubscriber.c | 9 ++------- .../t/040_pg_createsubscriber.pl | 19 ++++--------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index cb16a608002..4d705778454 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -2381,13 +2381,8 @@ main(int argc, char **argv) opt.config_file = pg_strdup(optarg); break; case 2: - if (!simple_string_list_member(&opt.pub_names, optarg)) - { - simple_string_list_append(&opt.pub_names, optarg); - num_pubs++; - } - else - pg_fatal("publication \"%s\" specified more than once for --publication", optarg); + simple_string_list_append(&opt.pub_names, optarg); + num_pubs++; break; case 3: if (!simple_string_list_member(&opt.replslot_names, optarg)) diff --git a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl index 858082c70df..9252d1c3c5c 100644 --- a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl +++ b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl @@ -67,18 +67,6 @@ command_fails( '--database' => 'pg1', ], 'duplicate database name'); -command_fails( - [ - 'pg_createsubscriber', - '--verbose', - '--pgdata' => $datadir, - '--publisher-server' => 'port=5432', - '--publication' => 'foo1', - '--publication' => 'foo1', - '--database' => 'pg1', - '--database' => 'pg2', - ], - 'duplicate publication name'); command_fails( [ 'pg_createsubscriber', @@ -346,7 +334,8 @@ is($node_s->safe_psql($db1, "SELECT COUNT(*) FROM pg_publication"), $node_s->stop; -# dry run mode on node S +# dry run mode on node S. Use the same publication name for different +# databases, since publication names are database-local. command_ok( [ 'pg_createsubscriber', @@ -357,8 +346,8 @@ command_ok( '--publisher-server' => $node_p->connstr($db1), '--socketdir' => $node_s->host, '--subscriber-port' => $node_s->port, - '--publication' => 'pub1', - '--publication' => 'pub2', + '--publication' => 'same_pub', + '--publication' => 'same_pub', '--subscription' => 'sub1', '--subscription' => 'sub2', '--database' => $db1, -- 2.50.1 (Apple Git-155)