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.94.2) (envelope-from ) id 1trWpJ-0055LU-Bi for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Mar 2025 06:41:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1trWpH-004dlW-3T for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Mar 2025 06:41:23 +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.94.2) (envelope-from ) id 1trWpG-004dkR-Ni for pgsql-hackers@lists.postgresql.org; Mon, 10 Mar 2025 06:41:22 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1trWpC-001z0H-32 for pgsql-hackers@lists.postgresql.org; Mon, 10 Mar 2025 06:41:22 +0000 Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-6dcd4f1aaccso61142246d6.2 for ; Sun, 09 Mar 2025 23:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741588878; x=1742193678; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vih31bjLD90edy6jYQo8WX3gO6oX5jeH7oS4w2H8NsQ=; b=hGJBQKRvaReWgeY/juG20Zgk855KXx33tTBEAFd95PPtE3rftZ9eV0vyQs2a9Q5wN1 YhPKfcbm8HCdFff/nhD2bgcdYl3WMURReFPzJKWC3aUnqTANCxo4z1BVarxA0ISmOXgg bd0dJf+dKMkxEwfS+bxUGryj3ms5QORe0o9HTRyaIWjqedhKFevn1hoguI09klcWNWgo x2sSHvPZcgF+iNZMHtUSCViFnGqoFYh4GsWBwzGXEMu6P53QIYxI0we1C2mv0E3RiEDX qyk7rrWCBLe2VPBnGGPGpKM2iG2Ro+L9SimByKc76EUdlgBi2cFXpg84XGiwWAy1XM8z nJpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741588878; x=1742193678; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vih31bjLD90edy6jYQo8WX3gO6oX5jeH7oS4w2H8NsQ=; b=UxrD9BCy1mb8lQxwg4IkHIOvyTZz6E8WJVGkLLtjUF1jibCfRRzjONpX8kfbWueyBo oaXH0TWRRujuwjZp7IsU+oUKAW+GLH3LOY3yM/JmztdG22fIwBOUj3DdXoyXFxR7/6qv VYyWge+Tgi67k3oYcuUwxccCS30jN6nGEIffKAQb0ci8471n0OfNXTAMPipZySRg4KWR ThpleZJqm1PoF+FB4KnkM4cNDsW5NdoRqEJqDOcCM/3px+JaVqUTIUJasNavBd1QWmXT 68HnWxUmjHYf8ZrUNec1QNDV1qASzKkzNd9xodfqFCRy3/6xXJIHK8gJqeE1bn1jXNqC HxBA== X-Forwarded-Encrypted: i=1; AJvYcCWpMyrEloQV75jiTETf0ov9gHSmSbuyxLu2ovf1dMuB+fSaOiyO5kzcuodnMsU7dJ2h38RQ1PdMakPaIASO@lists.postgresql.org X-Gm-Message-State: AOJu0YzTencHlegYKMJrvCznrbB8Sk0SWNuO3rzWJ8xik4aIJ+Nt4/Z8 zKczq35h7zs2Qy5zprm9Yw6T37yiN4v4WwuZYLdSvWZrHfQBlnaa8HUt5mGW6VK1YIZSBYA8Vz2 VvLvTrSbzayE28ny1/pm4ATsPdXw= X-Gm-Gg: ASbGncu4mwss4nseYnrolARLHhNOzlyRqoMZzElYQifiPJBuGbXOR+wSqa6AZCfH9pL ijiMKIHxRFmV1UGgB83J9Tg04DBFmR7ZVf27ysqtth2zfiY+4oYg5FliX47B4eUMJWFj8XahZHK 5ITj1VIrNdUxbDaImdekc39pljtBHjEUVvtzdZ X-Google-Smtp-Source: AGHT+IGfW3Hte15V77aUcbDZeYix1Qtn2+bUpvG+qVZXLj746+HGxOLHBusycmO8we/0Pvp0UxlLeggYN1M3de0ULY0= X-Received: by 2002:a05:6214:2a4b:b0:6e6:5ec3:8688 with SMTP id 6a1803df08f44-6e900710a5bmr134638816d6.45.1741588878152; Sun, 09 Mar 2025 23:41:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shubham Khanna Date: Mon, 10 Mar 2025 12:11:06 +0530 X-Gm-Features: AQ5f1Jq5X4T_7YYpOoHlNvD3SCXN2ZesMLoMMrcoDUfwYJxU-PTIH-VG58TVX9c Message-ID: Subject: Re: Adding a '--clean-publisher-objects' option to 'pg_createsubscriber' utility. To: Peter Smith Cc: Nisha Moond , "Hayato Kuroda (Fujitsu)" , Shlok Kyal , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Mar 6, 2025 at 9:27=E2=80=AFAM Peter Smith = wrote: > > Hi Shubham. > > Some review comments for patch v13-0001. > > =3D=3D=3D=3D=3D=3D > GENERAL > > 1. > --cleanup-existing-publications > > I've never liked this proposed switch name much. > > e.g. why say "cleanup" instead of "drop"? What is the difference? > Saying drop is very explicit about what the switch will do. > e.g. why say "existing"? It seems redundant; you can't cleanup/drop > something that does not exist. > > My preference is one of: > --drop-publications > --drop-all-publications > > either of which seem nicely aligned with the descriptions in the usage an= d docs. > > Yeah, I know I have raised this same point before, but AFAICT the > reply was like "will revise it in the next patch version", but that > was many versions ago. I think it is important to settle the switch > name earlier than later because there will be many tentacles into the > code (vars, params, fields, comments) and docs if anything changes -- > so it is not a decision you want to leave till the end because it > could destabilise everything at the last minute. > I have updated the option name to '--drop-all-publications'. > =3D=3D=3D=3D=3D=3D > Commit message > > 2. > By default, publications are preserved to avoid unintended data loss. > > ~ > > Was there supposed to be a blank line before this text, or should this > text be wrapped into the preceding paragraph? > Fixed. > =3D=3D=3D=3D=3D=3D > src/bin/pg_basebackup/pg_createsubscriber.c > > setup_subscriber: > > 3. > /* > * Create the subscriptions, adjust the initial location for logical > * replication and enable the subscriptions. That's the last step for lo= gical > - * replication setup. > + * replication setup. If 'drop_publications' options is true, existing > + * publications on the subscriber will be dropped before creating new > + * subscriptions. > */ > > There are multiple things amiss with this comment. > - 'drop_publications' is not the parameter name > - 'drop_publications' options [sic plural??]. It is not an option > here; it is a parameter > Fixed. > ~~~ > > check_and_drop_existing_publications: > > 4. > /* > - * Remove publication if it couldn't finish all steps. > + * Check and drop existing publications on the subscriber if requested. > */ > > There is no need to say "if requested.". It is akin to saying this > function does XXX if this function is called. > Fixed. > ~~~ > > drop_publication_by_name: > > 5. > +/* Drop the specified publication of the given database. */ > +static void > +drop_publication_by_name(PGconn *conn, const char *pubname, const char *= dbname) > > 5a. > I think it is better to define this function before > check_and_drop_existing_publications. YMMV. > > ~ > > 5b. > IMO the parameters should be reordered (PGconn *conn, const char > *dbname, const char *pubname). It seems more natural and would be > consistent with check_and_drop_existing_publications. YMMV. > > ~~~ Fixed. > > 6. > - dbinfo->pubname, dbinfo->dbname, PQresultErrorMessage(res)); > - dbinfo->made_publication =3D false; /* don't try again. */ > + pubname, dbname, PQresultErrorMessage(res)); > + dbinfos.dbinfo->made_publication =3D false; /* don't try again. */ > > Something about this flag assignment seems odd to me. IIUC > 'made_publications' is for removing the cleanup_objects_atexit to be > able to remove the special publication implicitly made by the > pg_createsubscriber. But, AFAIK we can also get to this code via the > --cleanup-existing-publication switch, so actually it might be one of > the "existing" publication DROPS that has failed. If so, then the > "don't try again comment" is misleading because it may not be that > same publication "again" at all. > I agree with your point. The current comment is misleading, as the failure could be related to an existing publication drop via --cleanup-existing-publications now --drop-all-publications, not just the publication created by pg_createsubscriber. This issue is still open, and I will address it in the next version of the patch. > =3D=3D=3D=3D=3D=3D > .../t/040_pg_createsubscriber.pl > > GENERAL. > > 7. > Most of the changes to this test code are just changing node name S -> > S1. It's not much to do with the patch other than tidying it in > preparation for a new node S2. OTOH it makes the review far harder > because there are so many changes. IMO all this S->S1 stuff should be > done as a separate pre-requisite patch and then it will be far easier > to see what changes are added for the --clean-existing-publications > testing. > > ~~~ > I understand your concern. Since I am using two nodes (node_s1 and node_s2), I will work on creating a separate prerequisite patch for renaming S -> S1. This should make it easier to review the actual changes related to --cleanup-existing-publications now --drop-all-publications testing. > 8. > # Set up node S as standby linking to node P > $node_p->backup('backup_1'); > -my $node_s =3D PostgreSQL::Test::Cluster->new('node_s'); > -$node_s->init_from_backup($node_p, 'backup_1', has_streaming =3D> 1); > -$node_s->append_conf( > +my $node_s1 =3D PostgreSQL::Test::Cluster->new('node_s1'); > +$node_s1->init_from_backup($node_p, 'backup_1', has_streaming =3D> 1); > +$node_s1->append_conf( > > The comment should refer to S1, not S. > > ~~~ > Fixed. > 9. > # Set up node C as standby linking to node S > -$node_s->backup('backup_2'); > +$node_s1->backup('backup_2'); > my $node_c =3D PostgreSQL::Test::Cluster->new('node_c'); > -$node_c->init_from_backup($node_s, 'backup_2', has_streaming =3D> 1); > +$node_c->init_from_backup($node_s1, 'backup_2', has_streaming =3D> 1); > > The comment should refer to S1, not S. > > ~~~ > Fixed. > 10. > # Check some unmet conditions on node S > -$node_s->append_conf( > +$node_s1->append_conf( > > The comment should refer to S1, not S. > > (note... there are lots of these. You should search/fix them all; > these review comments might miss some) > > ~~~ > Fixed. > 11. > + '--socketdir' =3D> $node_s1->host, > + '--subscriber-port' =3D> $node_s1->port, > '--database' =3D> $db1, > '--database' =3D> $db2, > ], > 'standby contains unmet conditions on node S'); > > The message should refer to S1, not S. > > (note... there are lots of these. You should search/fix them all; > these review comments might miss some) > > ~~~ > Fixed. > 12. > # dry run mode on node S > command_ok( > @@ -338,10 +353,10 @@ command_ok( > '--verbose', > '--dry-run', > '--recovery-timeout' =3D> $PostgreSQL::Test::Utils::timeout_default, > - '--pgdata' =3D> $node_s->data_dir, > + '--pgdata' =3D> $node_s1->data_dir, > '--publisher-server' =3D> $node_p->connstr($db1), > - '--socketdir' =3D> $node_s->host, > - '--subscriber-port' =3D> $node_s->port, > + '--socketdir' =3D> $node_s1->host, > + '--subscriber-port' =3D> $node_s1->port, > '--publication' =3D> 'pub1', > '--publication' =3D> 'pub2', > '--subscription' =3D> 'sub1', > @@ -352,10 +367,11 @@ command_ok( > 'run pg_createsubscriber --dry-run on node S'); > Comment and Message should refer to S1, not S. > > ~~~ Fixed. > > 13. > # Check if node S is still a standby > -$node_s->start; > -is($node_s->safe_psql('postgres', 'SELECT pg_catalog.pg_is_in_recovery()= '), > - 't', 'standby is in recovery'); > -$node_s->stop; > +$node_s1->start; > +is( $node_s1->safe_psql('postgres', 'SELECT pg_catalog.pg_is_in_recovery= ()'), > + 't', > + 'standby is in recovery'); > +$node_s1->stop; > > The comment should refer to S1, not S. > > ~~~ Fixed. > > 14. > -# Run pg_createsubscriber on node S. --verbose is used twice > -# to show more information. > +# Run pg_createsubscriber on node S using '--cleanup-existing-publicatio= ns'. > +# --verbose is used twice to show more information. > # In passing, also test the --enable-two-phase option > command_ok( > [ > 'pg_createsubscriber', > '--verbose', '--verbose', > '--recovery-timeout' =3D> $PostgreSQL::Test::Utils::timeout_default, > - '--pgdata' =3D> $node_s->data_dir, > + '--pgdata' =3D> $node_s1->data_dir, > '--publisher-server' =3D> $node_p->connstr($db1), > - '--socketdir' =3D> $node_s->host, > - '--subscriber-port' =3D> $node_s->port, > + '--socketdir' =3D> $node_s1->host, > + '--subscriber-port' =3D> $node_s1->port, > '--publication' =3D> 'pub1', > '--publication' =3D> 'pub2', > '--replication-slot' =3D> 'replslot1', > '--replication-slot' =3D> 'replslot2', > '--database' =3D> $db1, > '--database' =3D> $db2, > - '--enable-two-phase' > + '--enable-two-phase', > + '--cleanup-existing-publications', > ], > 'run pg_createsubscriber on node S'); > > Comment and Message should refer to S1, not S. > > ~~~ > Fixed. > 15. > +# Create user-defined publications > +$node_p->safe_psql($db3, "CREATE PUBLICATION test_pub3 FOR ALL TABLES;")= ; > +$node_p->safe_psql($db3, "CREATE PUBLICATION test_pub4 FOR ALL TABLES;")= ; > > Probably these can be combined. > > ~~~ > Fixed. > 16. > +# Drop the newly created publications > +$node_p->safe_psql($db3, "DROP PUBLICATION IF EXISTS test_pub3;"); > +$node_p->safe_psql($db3, "DROP PUBLICATION IF EXISTS test_pub4;"); > + > > Probably these can be combined. > Fixed. The attached patch at [1] contains the required changes. [1] - https://www.postgresql.org/message-id/CAHv8RjLCZyzFMGR8SBdvSocRZGAAr_= eRd4ht48kXCp9oEaKQeQ%40mail.gmail.com Thanks and regards, Shubham Khanna.