]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pg_createsubscriber: Fix duplicate publication name rejection.
authorAmit Kapila <akapila@postgresql.org>
Mon, 8 Jun 2026 06:49:29 +0000 (12:19 +0530)
committerAmit Kapila <akapila@postgresql.org>
Mon, 8 Jun 2026 06:49:29 +0000 (12:19 +0530)
pg_createsubscriber rejected duplicate --publication values while parsing
command-line options, even when the duplicate names referred to
publications in different databases. Since publication names are
database-local objects, the same name is perfectly valid across multiple
databases.

This restriction was not a practical problem before commit 85ddcc2f4c,
which added support for reusing pre-existing publications. After that
change, users who have identically-named publications in multiple
databases (a common convention) could not use the feature without renaming
their publications.

The analogous restriction on --subscription names is intentionally kept as
they are reused as replication slot names, which are cluster-global, so
allowing duplicate subscription names without additional guards could
cause a slot-name collision. That work is left for a future release.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Discussion: https://postgr.es/m/B08A7C89-B3DE-4C1D-A671-32AD8BAB7E22@gmail.com

src/bin/pg_basebackup/pg_createsubscriber.c
src/bin/pg_basebackup/t/040_pg_createsubscriber.pl

index cb16a60800280503a983476a518580299068834c..4d705778454bc49ed08fc013749eed7c36e431de 100644 (file)
@@ -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))
index 858082c70dfdd1a5f3be5ad8fff4b56cff459b64..9252d1c3c5c28ced753b582d4cf24a7d0ba485de 100644 (file)
@@ -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,