From: Chao Li <li.evan.chao@gmail.com>
To: Peter Smith <smithpb2250@gmail.com>
Cc: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Subject: Re: pg_createsubscriber: allow duplicate subscription names
Date: Fri, 7 Aug 2026 10:55:12 +0800
Message-ID: <7E5ECCC7-B506-4AE8-A3CC-5C23EF8E7375@gmail.com> (raw)
In-Reply-To: <CAHut+Pu-wh-7fdv38uG+CdAB=EZQ_okY3r_hA6RJknCRj1WeYg@mail.gmail.com>
References: <2B037930-9B7F-41D3-98B3-E50FFD94C01A@gmail.com>
<OS9PR01MB12149D2214320C1ABABBCEEB3F5D22@OS9PR01MB12149.jpnprd01.prod.outlook.com>
<59AFF62A-A206-4513-9B50-908E1FEA392C@gmail.com>
<CAHut+Pu-wh-7fdv38uG+CdAB=EZQ_okY3r_hA6RJknCRj1WeYg@mail.gmail.com>
> On Aug 7, 2026, at 08:24, Peter Smith <smithpb2250@gmail.com> wrote:
>
> Some minor review comments for patch v2. Nothing functional.
Thank you very much for reviewing.
>
> ======
> doc/src/sgml/ref/pg_createsubscriber.sgml
>
> 1.
> is reported. The order of the multiple subscription name switches must
> match the order of database switches. If this option is not specified,
> a generated name is assigned to the subscription name. This
> option cannot
> - be used together with <option>--all</option>.
> + be used together with <option>--all</option>. The same
> subscription name
> + can be used in different databases only when replication slot names are
> + specified with <option>--replication-slot</option>.
> </para>
>
> The new sentence LGTM. But my AI is pointing out that now the "-all"
> sentence sits wedged between the parts describing names (order of
> names, generated names, same names). It recommends moving the "--all"
> sentence like below:
>
> SUGGESTION
> The subscription name to set up the logical replication. This option
> cannot be used together with --all. Multiple subscriptions can be
> specified by writing multiple --subscription switches. The number of
> subscription names must match the number of specified databases,
> otherwise an error is reported. The order of the multiple subscription
> name switches must match the order of database switches. If this
> option is not specified, a generated name is assigned to the
> subscription name. The same subscription name can be used in
> different databases only when replication slot names are specified
> with --replication-slot.
>
Accepted.
>
> ======
> src/bin/pg_basebackup/pg_createsubscriber.c
>
> 2.
> int option_index;
> + bool duplicate_sub_name = false;
>
> Should it be plural?
>
> /duplicate_sub_name/duplicate_sub_names/
>
Accepted.
> ~~~
>
> 3.
> + if (simple_string_list_member(&opt.sub_names, optarg))
> + duplicate_sub_name = true;
>
> Having found at least one duplicate, you don't really need to keep checking.
>
> SUGGESTION
> if (!duplicate_sub_name)
> duplicate_sub_name = simple_string_list_member(&opt.sub_names, optarg);
>
> Anyway, the extra checking is cheap, so feel free to ignore this comment.
>
Okay, why not.
> ~~~
>
> 4.
> if (num_replslots > 0 && num_replslots != num_dbs)
> {
> pg_log_error("wrong number of replication slot names specified");
> pg_log_error_detail("The number of specified replication slot names
> (%d) must match the number of specified database names (%d).",
> num_replslots, num_dbs);
> exit(1);
> }
> if (duplicate_sub_name && num_replslots == 0)
> {
> pg_log_error("duplicate subscription names require replication slot names");
> pg_log_error_hint("Specify --replication-slot for each database.");
> exit(1);
> }
>
> The code LGTM, but would it be tidier to avoid multiple
> `num_replslots` checks by combining as a single if/else?
>
> SUGGESTION
> if (num_replslots == 0)
> {
> if (duplicate_sub_name)
> {
> pg_log_error ...
> }
> }
> else
> {
> if (num_replslots != num_dbs)
> {
> pg_log_error ...
> }
> }
>
Accepted.
PFA v3: addressed Peter’s comments.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/Attachments:v3-0001-pg_createsubscriber-Allow-duplicate-subscription-.patch (application/octet-stream, 6.1K) download
From 52524a8e63a34c1aebbbdd598f9322409946151f Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Wed, 5 Aug 2026 15:11:13 +0800
Subject: [PATCH v3] pg_createsubscriber: Allow duplicate subscription names
Subscription names are database-local, so the same name can be used in
different databases. However, pg_createsubscriber rejected duplicate
--subscription values unconditionally.
Allow duplicate subscription names when distinct replication slot names
are specified explicitly. Continue to reject them when
--replication-slot is omitted, because subscription names are then reused
as replication slot names, which must be unique within a cluster.
Add tests and update the documentation.
Suggested-by: Amit Kapila <amit.kapila16@gmail.com>
Author: Chao Li <lic@highgo.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Discussion: https://postgr.es/m/2B037930-9B7F-41D3-98B3-E50FFD94C01A@gmail.com
---
doc/src/sgml/ref/pg_createsubscriber.sgml | 9 ++++---
src/bin/pg_basebackup/pg_createsubscriber.c | 23 +++++++++++-------
.../t/040_pg_createsubscriber.pl | 24 +++++++++++++++----
3 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/doc/src/sgml/ref/pg_createsubscriber.sgml b/doc/src/sgml/ref/pg_createsubscriber.sgmlindex 193f60628bc..78a2596f72e 100644--- a/doc/src/sgml/ref/pg_createsubscriber.sgml+++ b/doc/src/sgml/ref/pg_createsubscriber.sgml@@ -355,14 +355,17 @@ PostgreSQL documentation
<term><option>--subscription=<replaceable class="parameter">name</replaceable></option></term>
<listitem>
<para>
- The subscription name to set up the logical replication. Multiple+ The subscription name to set up the logical replication. This option+ cannot be used together with <option>--all</option>. Multiple
subscriptions can be specified by writing multiple
<option>--subscription</option> switches. The number of subscription
names must match the number of specified databases, otherwise an error
is reported. The order of the multiple subscription name switches must
match the order of database switches. If this option is not specified,
- a generated name is assigned to the subscription name. This option cannot- be used together with <option>--all</option>.+ a generated name is assigned to the subscription name. The same+ subscription name can be used in different databases only when+ replication slot names are specified with+ <option>--replication-slot</option>.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.cindex 20b354aed56..5d834edbe72 100644--- a/src/bin/pg_basebackup/pg_createsubscriber.c+++ b/src/bin/pg_basebackup/pg_createsubscriber.c@@ -2262,6 +2262,7 @@ main(int argc, char **argv)
int c;
int option_index;
+ bool duplicate_sub_names = false;
char *pub_base_conninfo;
char *sub_base_conninfo;
@@ -2394,13 +2395,10 @@ 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);+ if (!duplicate_sub_names)+ duplicate_sub_names = simple_string_list_member(&opt.sub_names, optarg);+ simple_string_list_append(&opt.sub_names, optarg);+ num_subs++;
break;
case 5:
if (!simple_string_list_member(&opt.objecttypes_to_clean, optarg))
@@ -2580,7 +2578,16 @@ main(int argc, char **argv)
num_subs, num_dbs);
exit(1);
}
- if (num_replslots > 0 && num_replslots != num_dbs)+ if (num_replslots == 0)+ {+ if (duplicate_sub_names)+ {+ pg_log_error("duplicate subscription names require replication slot names");+ pg_log_error_hint("Specify --replication-slot for each database.");+ exit(1);+ }+ }+ else if (num_replslots != num_dbs)
{
pg_log_error("wrong number of replication slot names specified");
pg_log_error_detail("The number of specified replication slot names (%d) must match the number of specified database names (%d).",
diff --git a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl b/src/bin/pg_basebackup/t/040_pg_createsubscriber.plindex 9252d1c3c5c..7b381637574 100644--- a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl+++ b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl@@ -91,6 +91,19 @@ command_fails(
'--database' => 'pg2',
],
'wrong number of subscription names');
+command_fails_like(+ [+ 'pg_createsubscriber',+ '--verbose',+ '--pgdata' => $datadir,+ '--publisher-server' => 'port=5432',+ '--subscription' => 'bar1',+ '--subscription' => 'bar1',+ '--database' => 'pg1',+ '--database' => 'pg2',+ ],+ qr/duplicate subscription names require replication slot names/,+ 'duplicate subscription names without replication slot names');
command_fails(
[
'pg_createsubscriber',
@@ -334,8 +347,9 @@ 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 both names are database-local. Replication slot+# names are specified because replication slots are cluster-global.
command_ok(
[
'pg_createsubscriber',
@@ -348,8 +362,10 @@ command_ok(
'--subscriber-port' => $node_s->port,
'--publication' => 'same_pub',
'--publication' => 'same_pub',
- '--subscription' => 'sub1',- '--subscription' => 'sub2',+ '--subscription' => 'same_sub',+ '--subscription' => 'same_sub',+ '--replication-slot' => 'slot1',+ '--replication-slot' => 'slot2',
'--database' => $db1,
'--database' => $db2,
'--logdir' => $logdir,
--
2.50.1 (Apple Git-155)
=
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: li.evan.chao@gmail.com, smithpb2250@gmail.com, kuroda.hayato@fujitsu.com, amit.kapila16@gmail.com
Subject: Re: pg_createsubscriber: allow duplicate subscription names
In-Reply-To: <7E5ECCC7-B506-4AE8-A3CC-5C23EF8E7375@gmail.com>
References: <2B037930-9B7F-41D3-98B3-E50FFD94C01A@gmail.com> <OS9PR01MB12149D2214320C1ABABBCEEB3F5D22@OS9PR01MB12149.jpnprd01.prod.outlook.com> <59AFF62A-A206-4513-9B50-908E1FEA392C@gmail.com> <CAHut+Pu-wh-7fdv38uG+CdAB=EZQ_okY3r_hA6RJknCRj1WeYg@mail.gmail.com> <7E5ECCC7-B506-4AE8-A3CC-5C23EF8E7375@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox