pg_createsubscriber: Fix duplicate publication name rejection.

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
This commit is contained in:
Amit Kapila 2026-06-08 12:19:29 +05:30
parent b20c952ce7
commit 6ce035ffff
2 changed files with 6 additions and 22 deletions

View 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))

View 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,