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 1tiXyv-00HEAX-5G for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 12:06:13 +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 1tiXyt-006WlJ-5Q for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 12:06:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tiXys-006Wl9-OY for pgsql-hackers@lists.postgresql.org; Thu, 13 Feb 2025 12:06:11 +0000 Received: from mail-yw1-x112d.google.com ([2607:f8b0:4864:20::112d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tiXyq-000Zjr-18 for pgsql-hackers@lists.postgresql.org; Thu, 13 Feb 2025 12:06:10 +0000 Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-6fb0e9e6f6bso6289007b3.2 for ; Thu, 13 Feb 2025 04:06:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739448367; x=1740053167; 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=WvuJuQP7sRXWRkGs+ISL8pFZNX0NFA8Dm16GJWxKydQ=; b=OZXZRO+f5xQJmsgHZCtVApkh8rPnQz/Eqrj9Dg8aSZ02DlRXRFNH3QIYZ69E0FYcMV n0iRLr5q0Vg/EdUtYBgZ85aELn4UJjCGVRg5ydqK9q9wu5rXsGaEvTrMKuGCM+aRjRVw 1PDg0dFg5QLkBUGL+IxA2ZdFb7oHSymNBJ6j9Bevtl2JI7oyM4LwUEYohU3+jpwxmWHF y/ZfcqVQIKPjCkOZrj/4qQWNHt5qSmUhiWYJgoRl3lCZ2EaapwYhnfc1SI704S3N9iR3 QMvI1hPaC8XENkiZ1zYXAdev4bHlfH8uid0ZZ7eheagXAsCeGHmQ7GJmP3yVCq+/UtK+ dm/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739448367; x=1740053167; 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=WvuJuQP7sRXWRkGs+ISL8pFZNX0NFA8Dm16GJWxKydQ=; b=bl6XZUdDg4cmP4dQOGd3KnJKoYol3HerW3PWJR/yjwGotydx1ipobmIG1RhyglpAL4 8LkTReP147tDAOxe789aJKOWI1dFiDJ8xpsKX+Bm0O53By0mCjTzPGJBcpE2hfYMCrBM QOTL2zpDM8J6uRz0SSp5A2dXf8vsSYl5JjiLOfkNS/cM6xKtP3AnJ4O9wXQi2N1xUjIG vOc47wwWmXuolvNRngtA4eC0oXWbAiJ/XJuRFn1SZ5kaKZJ0uz4eoW3QOXxSbApDEYAP A67Xxp//1OgBnX4yxLJjH6ePRJfL1rjzCnXRZNqR5jIuZFxjRSrAHVKwfkKhufqi7KEy LkMQ== X-Forwarded-Encrypted: i=1; AJvYcCXgwCb8WOVTziR10A4Eslq+FmLEqaw2ci6E2Bs6X2g3VlHutNkmNgwfS8jneOKRGl0GIguKdqzLXSzPupBi@lists.postgresql.org X-Gm-Message-State: AOJu0YyDmaIFSNR/lWe3KspIUrcQxUD7KGO+TJrTPlmuKhPrCePXGr0I 2f4CrQcvwkVM1hGD8Vw+FOE5+PBHeqfTSLaVrzHWRPHpx8K+5yCaQgIMNhbbVtl7qgg5V4Dy6iM xEQPxDw4twEvfwM9vgppu0qna+Tk= X-Gm-Gg: ASbGncvfKxlo+Dv72b8NhDuPgMwWUGV4XlFjNXAfuG67LDa8n+yGdW2q2P6Wg8raTvL GKxpO2KrQiot2uYDWsD0FMGKjGT/yNlMR0SmjROm1S/3JJHac2l95GOwKEMKqpq/gUUKODlJjdf g= X-Google-Smtp-Source: AGHT+IH5DeFCC90EzEYRetcjS0kNiwRN5b8HYRrKgjaQuA0aGSqclhOveH1qOWRxWTCe3fobJIHEciFsoFsNb5gnf1o= X-Received: by 2002:a05:690c:a8b:b0:6f2:96e7:8afc with SMTP id 00721157ae682-6fb32c4913cmr29662627b3.3.1739448367483; Thu, 13 Feb 2025 04:06:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Shlok Kyal Date: Thu, 13 Feb 2025 17:35:56 +0530 X-Gm-Features: AWEUYZn5DVY0iciR0IVLCGmhqHdkDPPqhtCNiYjo5uD52Rpy86vBDhpfHFsf2Y4 Message-ID: Subject: Re: Adding a '--clean-publisher-objects' option to 'pg_createsubscriber' utility. To: Shubham Khanna Cc: "Hayato Kuroda (Fujitsu)" , 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, 13 Feb 2025 at 15:20, Shubham Khanna wrote: > > On Tue, Feb 11, 2025 at 9:56=E2=80=AFPM Shlok Kyal wrote: > > > > On Tue, 11 Feb 2025 at 09:51, Shubham Khanna > > wrote: > > > > > > On Fri, Feb 7, 2025 at 7:46=E2=80=AFAM Hayato Kuroda (Fujitsu) > > > wrote: > > > > > > > > Dear Shubham, > > > > > > > > Thanks for updating the patch. > > > > > > > > Previously you told that you had a plan to extend the patch to drop= other replication > > > > objects [1], but I think it is not needed. pg_createsubscriber has = already been > > > > able to drop the existing subscrisubscriptions in check_and_drop_ex= isting_subscriptions(). > > > > As for the replication slot, I have told in [2], it would be create= d intentionally > > > > thus I feel it should not be dropped. > > > > Thus I regard the patch does not have concrete extending plan. > > > > > > > > Below part contains my review comment. > > > > > > > > 01. Option name > > > > > > > > Based on the above discussion, "--cleanup-publisher-objects" is not= suitable because > > > > it won't drop replication slots. How about "--cleanup-publications"= ? > > > > > > > > > > I have changed the name of the option to "--cleanup-existing-publica= tions" > > > > > > > 02. usage() > > > > ``` > > > > + printf(_(" -C --cleanup-publisher-objects drop all public= ations on the logical replica\n")); > > > > ``` > > > > > > Fixed. > > > > > > > s/logical replica/subscriber > > > > > > > > 03. drop_all_publications > > > > ``` > > > > +/* Drops all existing logical replication publications from all su= bscriber > > > > + * databases > > > > + */ > > > > +static void > > > > ``` > > > > > > > > Initial line of the comment must be blank [3]. > > > > > > > > > > Removed this function. > > > > > > > 04. main > > > > ``` > > > > + {"cleanup-publisher-objects", no_argument, NULL, 'C= '}, > > > > ``` > > > > > > > > Is there a reason why upper case is used? I feel lower one is enoug= h. > > > > > > > > > > Fixed. > > > > > > > 05. main > > > > ``` > > > > + /* Drop publications from the subscriber if requested */ > > > > + if (opt.cleanup_publisher_objects) > > > > + drop_all_publications(dbinfo); > > > > ``` > > > > > > > > After considering more, I noticed that we have already called drop_= publication() > > > > in the setup_subscriber(). Can we call drop_all_publications() ther= e instead when > > > > -C is specified? > > > > > > > > > > I agree with you on this. I have removed the drop_all_publication() > > > and added the "--cleanup-existing-publications" option to the > > > drop_publication() > > > > > > > 06. 040_pg_createsubscriber.pl > > > > > > > > ``` > > > > +$node_s->start; > > > > +# Create publications to test it's removal > > > > +$node_p->safe_psql($db1, "CREATE PUBLICATION test_pub FOR ALL TABL= ES;"); > > > > +$node_p->safe_psql($db1, "CREATE PUBLICATION test_pub2 FOR ALL TAB= LES;"); > > > > + > > > > +# Verify the existing publications > > > > +my $pub_count_before =3D > > > > + $node_s->safe_psql($db1, "SELECT COUNT(*) FROM pg_publication;")= ; > > > > +is($pub_count_before, '2', > > > > + 'two publications created before --cleanup-publisher-object= s is run'); > > > > + > > > > +$node_s->stop; > > > > ``` > > > > > > > > I feel it requires unnecessary startup and shutdown. IIUC, creating= publications and check > > > > counts can be before stopping the node_s, around line 331. > > > > > > > > > > Fixed. > > > > > > > 07. 040_pg_createsubscriber.pl > > > > > > > > ``` > > > > +$node_p->safe_psql($db1, "CREATE PUBLICATION test_pub FOR ALL TABL= ES;"); > > > > +$node_p->safe_psql($db1, "CREATE PUBLICATION test_pub2 FOR ALL TAB= LES;"); > > > > + > > > > +# Verify the existing publications > > > > +my $pub_count_before =3D > > > > + $node_s->safe_psql($db1, "SELECT COUNT(*) FROM pg_publication;")= ; > > > > +is($pub_count_before, '2', > > > > + 'two publications created before --cleanup-publisher-object= s is run'); > > > > + > > > > ``` > > > > > > > > Also, there is a possibility that CREATE PUBLICATION on node_p is n= ot replicated yet > > > > when SELECT COUNT(*) is executed. Please wait for the replay. > > > > > > > > [1]: https://www.postgresql.org/message-id/CAHv8RjL4OvoYafofTb_U_JD= 5HuyoNowBoGpMfnEbhDSENA74Kg%40mail.gmail.com > > > > [2]: https://www.postgresql.org/message-id/OSCPR01MB1496664FDC38DA4= 0A441F449FF5EE2%40OSCPR01MB14966.jpnprd01.prod.outlook.com > > > > [3]: https://www.postgresql.org/docs/devel/source-format.html > > > > > > > > > > Fixed. > > > > > > The attached Patch contains the suggested changes. > > > > > > > Hi Shubham, > > > > I have some comments for v4 patch: > > 1. I think we should update the comment for the function > > 'drop_publication'. As its usage is changed with this patch > > Currently it states: > > /* > > * Remove publication if it couldn't finish all steps. > > */ > > > > Fixed. > > > 2. In case when --cleanup_existing_publications is not specified the > > info message has two double quotes. > > > > pg_createsubscriber: dropping publication > > ""pg_createsubscriber_5_aa3c31f2"" in database "postgres" > > > > The code: > > + appendPQExpBufferStr(targets, > > + PQescapeIdentifier(conn, dbinfo->pubname, > > + strlen(dbinfo->pubname)= )); > > > > It is appending the value along with the double quotes. I think we > > should assign the value of 'PQescapeIdentifier(conn, dbinfo->pubname, > > strlen(dbinfo->pubname)' to a string and then use it. > > > > Fixed. > > The attached patch contains the suggested changes. > Hi, I reviewed v5 patch, I have some comments: 1. I feel that from the description it is not clear from which node we are removing the publications. + Remove all existing publications from specified databases. Should we write it something like: Remove all existing publications from specified databases on the target ser= ver. Thoughts? 2. Based on observation in other files, I feel the description can be in next line: printf(_("\nOptions:\n")); + printf(_(" -c --cleanup-existing-publications drop all publications on the subscriber\n")); printf(_(" -d, --database=3DDBNAME database in which to create a subscription\n")); Something like + printf(_(" -c --cleanup-existing-publications\n" + drop all publications on the subscriber\n")); 3. Why are we using 'poll_query_until' +ok( $node_s->poll_query_until( + $db1, "SELECT COUNT(*) =3D 2 FROM pg_publication"), + 'two publications created before --cleanup-existing-publications is run')= ; + Should we use 'safe_psql'? Thanks and Regards, Shlok Kyal