Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wsAkX-000R5X-0x for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Aug 2026 02:55:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wsAkV-00714t-0J for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Aug 2026 02:55:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wsAkU-00714k-2V for pgsql-hackers@lists.postgresql.org; Fri, 07 Aug 2026 02:55:54 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wsAkR-00000000gTg-4B0d for pgsql-hackers@lists.postgresql.org; Fri, 07 Aug 2026 02:55:53 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2d049069377so30928885ad.0 for ; Thu, 06 Aug 2026 19:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786071350; x=1786676150; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pfPVuj63h8z9h+aSSHZuhAOQNDGBU9bN9nd1r2HELcg=; b=G2Sqh5axzafjO5+6fNComlEtdM/nAaMjya8Oz9wwUQ8aLntl1D+j/HT8mNGadYEMgN HZVa0kqPR5L9umsppG2tAZq2C60GAA2smtHLCXo8lSD/6mXuhgfxiYchFyqppiYA6wpG PFYd+UwhfOpu29kaWeBx/PaqgXr5Q/WJofxMsa62rZf+Zd1sP/TYPOP5wKnQG9DA5fff YrWpYV4/8LU4Dj+A5wDaX1newURz1sEmTfQ1hLPYbZa1zF0hHHvxvMqb4jufUoyB1UUx j0P0v5i4dgRIsYdt34ClrQod5ipyIbvyL2qaECRXZzP6LWMpV+Fq7ZeRXKDO8Y7ffE8S Ij0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786071350; x=1786676150; h=references:to:cc:in-reply-to:date:subject:mime-version:content-type :message-id:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pfPVuj63h8z9h+aSSHZuhAOQNDGBU9bN9nd1r2HELcg=; b=W6TFMvNlIkSCxo+zNyyCeNWeUPPkcoonHb4ez6ziIOu61TPMXzxkmytw0aLuuzZvOY 7qGCxIKpZ3fEo8sJ0XjseyM1xNOTTHq+Dzn0123XlqepLhQzJyk77cfp+2MBUigCwTvY BUl/Vaval0+sMc10HeBMi9f+xWGAPdhlPbRmre1JcV3/1Ys0jaBTLuMTJNE+SvLnIYPJ fzf302OQC66pyJh97yHmNI+MK2NHOCpowrrTQgGYRnALkPncuz0zmD/jGVzvrqkHtjZ1 F/3ioQpWceiruYI98L+xTIt3ubHmewnuTRI8/ImrJg5SNaDaGnsTXW4Tq/dHlS1/xeWo 6w9w== X-Forwarded-Encrypted: i=1; AHgh+RpDHqinK3ZkSURqYQwiZ+Tx2ux+I4jlRzB88B6wzgBrrenqFjrxjH+0HXZL5IHSBHssZqLz4I8g7rdDy0s2@lists.postgresql.org X-Gm-Message-State: AOJu0Yz169Y2hdyPgz8dagh3AXt2AE1ewYQHqQl7xEzomMXzcsJGxJMY BYgKSRdXU3JQ8UUbG3s0wk+KjrjdhDFk0kvd2rV+t4nMp+fdSrX9/6WZ X-Gm-Gg: AR+sD11b0417T48ry51jql6DjY6iUH6heXkHcpjw9pSjQhzPoETlLGDgmtby5j3VQLo P2FVow06c3kf69b/XZ5A5IvIMAOd9nYJcLy7GS0a8xxaB7YaqdNAxJMnIaoGrPNviuWhvCDZSs+ o7MIOyz/9n7Lyy2cV0YpuyJ6cBalcG8B05jvsPyhVDwThEHZ4f8B9AEmGlVfUF77srjpUAMcWr8 O3kaoqKhqwBDQ4qFZOGarhr4JOkwu8HCd+qsohAb1z+hOWk0G8pFNAEfN9110Fn8OIpZB1ljbsR DRIcEEBK85KR1KAnXYzRGQIpLwDqgaKxP+958Joyx1t0teCCK5LiV8r8ZXJYmhf7htHTuzKaf96 oGoolI7LqlOYrGKXdiFkdGk5TXR4+cIW66Xv8dL0e7LJlJSoMCyPvD4zpm7IU6C4AFW8MhEEvjH /ygV3CL0zZaWK5aya09eZ4VdeFu2XoS91JUnpXows4m+xLlZ0VLA8wZuDZNuBuI32tCz+JQAuRS 4h+jpto X-Received: by 2002:a05:6a21:4d0c:b0:3c3:7481:7a03 with SMTP id adf61e73a8af0-3cbadd27dfcmr8692373637.34.1786071349975; Thu, 06 Aug 2026 19:55:49 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.161]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cbe8bb43feesm161836a12.11.2026.08.06.19.55.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Aug 2026 19:55:49 -0700 (PDT) From: Chao Li Message-Id: <7E5ECCC7-B506-4AE8-A3CC-5C23EF8E7375@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_25EF8CE9-4D85-4D90-93CD-5A2A68659C17" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: pg_createsubscriber: allow duplicate subscription names Date: Fri, 7 Aug 2026 10:55:12 +0800 In-Reply-To: Cc: "Hayato Kuroda (Fujitsu)" , PostgreSQL Hackers , Amit Kapila To: Peter Smith References: <2B037930-9B7F-41D3-98B3-E50FFD94C01A@gmail.com> <59AFF62A-A206-4513-9B50-908E1FEA392C@gmail.com> X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_25EF8CE9-4D85-4D90-93CD-5A2A68659C17 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Aug 7, 2026, at 08:24, Peter Smith wrote: >=20 > Some minor review comments for patch v2. Nothing functional. Thank you very much for reviewing. >=20 > =3D=3D=3D=3D=3D=3D > doc/src/sgml/ref/pg_createsubscriber.sgml >=20 > 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 . > + be used together with . The same > subscription name > + can be used in different databases only when replication slot = names are > + specified with . > >=20 > 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: >=20 > 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. >=20 Accepted. >=20 > =3D=3D=3D=3D=3D=3D > src/bin/pg_basebackup/pg_createsubscriber.c >=20 > 2. > int option_index; > + bool duplicate_sub_name =3D false; >=20 > Should it be plural? >=20 > /duplicate_sub_name/duplicate_sub_names/ >=20 Accepted. > ~~~ >=20 > 3. > + if (simple_string_list_member(&opt.sub_names, optarg)) > + duplicate_sub_name =3D true; >=20 > Having found at least one duplicate, you don't really need to keep = checking. >=20 > SUGGESTION > if (!duplicate_sub_name) > duplicate_sub_name =3D simple_string_list_member(&opt.sub_names, = optarg); >=20 > Anyway, the extra checking is cheap, so feel free to ignore this = comment. >=20 Okay, why not. > ~~~ >=20 > 4. > if (num_replslots > 0 && num_replslots !=3D 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 =3D=3D 0) > { > pg_log_error("duplicate subscription names require replication slot = names"); > pg_log_error_hint("Specify --replication-slot for each database."); > exit(1); > } >=20 > The code LGTM, but would it be tidier to avoid multiple > `num_replslots` checks by combining as a single if/else? >=20 > SUGGESTION > if (num_replslots =3D=3D 0) > { > if (duplicate_sub_name) > { > pg_log_error ... > } > } > else > { > if (num_replslots !=3D num_dbs) > { > pg_log_error ... > } > } >=20 Accepted. PFA v3: addressed Peter=E2=80=99s comments. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_25EF8CE9-4D85-4D90-93CD-5A2A68659C17 Content-Disposition: attachment; filename=v3-0001-pg_createsubscriber-Allow-duplicate-subscription-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v3-0001-pg_createsubscriber-Allow-duplicate-subscription-.patch" Content-Transfer-Encoding: quoted-printable =46rom=2052524a8e63a34c1aebbbdd598f9322409946151f=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Wed,=205=20Aug=202026=2015:11:13=20+0800=0ASubject:=20[PATCH=20= v3]=20pg_createsubscriber:=20Allow=20duplicate=20subscription=20names=0A=0A= Subscription=20names=20are=20database-local,=20so=20the=20same=20name=20= can=20be=20used=20in=0Adifferent=20databases.=20=20However,=20= pg_createsubscriber=20rejected=20duplicate=0A--subscription=20values=20= unconditionally.=0A=0AAllow=20duplicate=20subscription=20names=20when=20= distinct=20replication=20slot=20names=0Aare=20specified=20explicitly.=20=20= Continue=20to=20reject=20them=20when=0A--replication-slot=20is=20= omitted,=20because=20subscription=20names=20are=20then=20reused=0Aas=20= replication=20slot=20names,=20which=20must=20be=20unique=20within=20a=20= cluster.=0A=0AAdd=20tests=20and=20update=20the=20documentation.=0A=0A= Suggested-by:=20Amit=20Kapila=20=0AAuthor:=20= Chao=20Li=20=0AReviewed-by:=20Hayato=20Kuroda=20= =0AReviewed-by:=20Peter=20Smith=20= =0ADiscussion:=20= https://postgr.es/m/2B037930-9B7F-41D3-98B3-E50FFD94C01A@gmail.com=0A---=0A= =20doc/src/sgml/ref/pg_createsubscriber.sgml=20=20=20=20=20|=20=209=20= ++++---=0A=20src/bin/pg_basebackup/pg_createsubscriber.c=20=20=20|=2023=20= +++++++++++-------=0A=20.../t/040_pg_createsubscriber.pl=20=20=20=20=20=20= =20=20=20=20=20=20=20=20|=2024=20+++++++++++++++----=0A=203=20files=20= changed,=2041=20insertions(+),=2015=20deletions(-)=0A=0Adiff=20--git=20= a/doc/src/sgml/ref/pg_createsubscriber.sgml=20= b/doc/src/sgml/ref/pg_createsubscriber.sgml=0Aindex=20= 193f60628bc..78a2596f72e=20100644=0A---=20= a/doc/src/sgml/ref/pg_createsubscriber.sgml=0A+++=20= b/doc/src/sgml/ref/pg_createsubscriber.sgml=0A@@=20-355,14=20+355,17=20= @@=20PostgreSQL=20documentation=0A=20=20=20=20=20=20= =0A=20=20=20=20=20=20= =0A=20=20=20=20=20=20=20=0A-=20=20=20=20=20=20=20The=20= subscription=20name=20to=20set=20up=20the=20logical=20replication.=20=20= Multiple=0A+=20=20=20=20=20=20=20The=20subscription=20name=20to=20set=20= up=20the=20logical=20replication.=20=20This=20option=0A+=20=20=20=20=20=20= =20cannot=20be=20used=20together=20with=20.=20=20= Multiple=0A=20=20=20=20=20=20=20=20subscriptions=20can=20be=20specified=20= by=20writing=20multiple=0A=20=20=20=20=20=20=20=20= =20switches.=20=20The=20number=20of=20= subscription=0A=20=20=20=20=20=20=20=20names=20must=20match=20the=20= number=20of=20specified=20databases,=20otherwise=20an=20error=0A=20=20=20= =20=20=20=20=20is=20reported.=20=20The=20order=20of=20the=20multiple=20= subscription=20name=20switches=20must=0A=20=20=20=20=20=20=20=20match=20= the=20order=20of=20database=20switches.=20=20If=20this=20option=20is=20= not=20specified,=0A-=20=20=20=20=20=20=20a=20generated=20name=20is=20= assigned=20to=20the=20subscription=20name.=20This=20option=20cannot=0A-=20= =20=20=20=20=20=20be=20used=20together=20with=20.=0A= +=20=20=20=20=20=20=20a=20generated=20name=20is=20assigned=20to=20the=20= subscription=20name.=20=20The=20same=0A+=20=20=20=20=20=20=20= subscription=20name=20can=20be=20used=20in=20different=20databases=20= only=20when=0A+=20=20=20=20=20=20=20replication=20slot=20names=20are=20= specified=20with=0A+=20=20=20=20=20=20=20= .=0A=20=20=20=20=20=20=20=0A=20= =20=20=20=20=20=0A=20=20=20=20=20=0Adiff=20= --git=20a/src/bin/pg_basebackup/pg_createsubscriber.c=20= b/src/bin/pg_basebackup/pg_createsubscriber.c=0Aindex=20= 20b354aed56..5d834edbe72=20100644=0A---=20= a/src/bin/pg_basebackup/pg_createsubscriber.c=0A+++=20= b/src/bin/pg_basebackup/pg_createsubscriber.c=0A@@=20-2262,6=20+2262,7=20= @@=20main(int=20argc,=20char=20**argv)=0A=20=0A=20=09int=09=09=09c;=0A=20= =09int=09=09=09option_index;=0A+=09bool=09=09duplicate_sub_names=20=3D=20= false;=0A=20=0A=20=09char=09=20=20=20*pub_base_conninfo;=0A=20=09char=09=20= =20=20*sub_base_conninfo;=0A@@=20-2394,13=20+2395,10=20@@=20main(int=20= argc,=20char=20**argv)=0A=20=09=09=09=09=09pg_fatal("replication=20slot=20= \"%s\"=20specified=20more=20than=20once=20for=20--replication-slot",=20= optarg);=0A=20=09=09=09=09break;=0A=20=09=09=09case=204:=0A-=09=09=09=09= if=20(!simple_string_list_member(&opt.sub_names,=20optarg))=0A-=09=09=09=09= {=0A-=09=09=09=09=09simple_string_list_append(&opt.sub_names,=20optarg);=0A= -=09=09=09=09=09num_subs++;=0A-=09=09=09=09}=0A-=09=09=09=09else=0A-=09=09= =09=09=09pg_fatal("subscription=20\"%s\"=20specified=20more=20than=20= once=20for=20--subscription",=20optarg);=0A+=09=09=09=09if=20= (!duplicate_sub_names)=0A+=09=09=09=09=09duplicate_sub_names=20=3D=20= simple_string_list_member(&opt.sub_names,=20optarg);=0A+=09=09=09=09= simple_string_list_append(&opt.sub_names,=20optarg);=0A+=09=09=09=09= num_subs++;=0A=20=09=09=09=09break;=0A=20=09=09=09case=205:=0A=20=09=09=09= =09if=20(!simple_string_list_member(&opt.objecttypes_to_clean,=20= optarg))=0A@@=20-2580,7=20+2578,16=20@@=20main(int=20argc,=20char=20= **argv)=0A=20=09=09=09=09=09=09=09num_subs,=20num_dbs);=0A=20=09=09= exit(1);=0A=20=09}=0A-=09if=20(num_replslots=20>=200=20&&=20= num_replslots=20!=3D=20num_dbs)=0A+=09if=20(num_replslots=20=3D=3D=200)=0A= +=09{=0A+=09=09if=20(duplicate_sub_names)=0A+=09=09{=0A+=09=09=09= pg_log_error("duplicate=20subscription=20names=20require=20replication=20= slot=20names");=0A+=09=09=09pg_log_error_hint("Specify=20= --replication-slot=20for=20each=20database.");=0A+=09=09=09exit(1);=0A+=09= =09}=0A+=09}=0A+=09else=20if=20(num_replslots=20!=3D=20num_dbs)=0A=20=09= {=0A=20=09=09pg_log_error("wrong=20number=20of=20replication=20slot=20= names=20specified");=0A=20=09=09pg_log_error_detail("The=20number=20of=20= specified=20replication=20slot=20names=20(%d)=20must=20match=20the=20= number=20of=20specified=20database=20names=20(%d).",=0Adiff=20--git=20= a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl=20= b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl=0Aindex=20= 9252d1c3c5c..7b381637574=20100644=0A---=20= a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl=0A+++=20= b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl=0A@@=20-91,6=20= +91,19=20@@=20command_fails(=0A=20=09=09'--database'=20=3D>=20'pg2',=0A=20= =09],=0A=20=09'wrong=20number=20of=20subscription=20names');=0A= +command_fails_like(=0A+=09[=0A+=09=09'pg_createsubscriber',=0A+=09=09= '--verbose',=0A+=09=09'--pgdata'=20=3D>=20$datadir,=0A+=09=09= '--publisher-server'=20=3D>=20'port=3D5432',=0A+=09=09'--subscription'=20= =3D>=20'bar1',=0A+=09=09'--subscription'=20=3D>=20'bar1',=0A+=09=09= '--database'=20=3D>=20'pg1',=0A+=09=09'--database'=20=3D>=20'pg2',=0A+=09= ],=0A+=09qr/duplicate=20subscription=20names=20require=20replication=20= slot=20names/,=0A+=09'duplicate=20subscription=20names=20without=20= replication=20slot=20names');=0A=20command_fails(=0A=20=09[=0A=20=09=09= 'pg_createsubscriber',=0A@@=20-334,8=20+347,9=20@@=20= is($node_s->safe_psql($db1,=20"SELECT=20COUNT(*)=20FROM=20= pg_publication"),=0A=20=0A=20$node_s->stop;=0A=20=0A-#=20dry=20run=20= mode=20on=20node=20S.=20Use=20the=20same=20publication=20name=20for=20= different=0A-#=20databases,=20since=20publication=20names=20are=20= database-local.=0A+#=20dry=20run=20mode=20on=20node=20S.=20Use=20the=20= same=20publication=20and=20subscription=20names=20for=0A+#=20different=20= databases,=20since=20both=20names=20are=20database-local.=20Replication=20= slot=0A+#=20names=20are=20specified=20because=20replication=20slots=20= are=20cluster-global.=0A=20command_ok(=0A=20=09[=0A=20=09=09= 'pg_createsubscriber',=0A@@=20-348,8=20+362,10=20@@=20command_ok(=0A=20=09= =09'--subscriber-port'=20=3D>=20$node_s->port,=0A=20=09=09= '--publication'=20=3D>=20'same_pub',=0A=20=09=09'--publication'=20=3D>=20= 'same_pub',=0A-=09=09'--subscription'=20=3D>=20'sub1',=0A-=09=09= '--subscription'=20=3D>=20'sub2',=0A+=09=09'--subscription'=20=3D>=20= 'same_sub',=0A+=09=09'--subscription'=20=3D>=20'same_sub',=0A+=09=09= '--replication-slot'=20=3D>=20'slot1',=0A+=09=09'--replication-slot'=20= =3D>=20'slot2',=0A=20=09=09'--database'=20=3D>=20$db1,=0A=20=09=09= '--database'=20=3D>=20$db2,=0A=20=09=09'--logdir'=20=3D>=20$logdir,=0A--=20= =0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_25EF8CE9-4D85-4D90-93CD-5A2A68659C17--