Re: Enhance 'pg_createsubscriber' to retrieve databases automatically when no database is provided.

From: vignesh C <vignesh21(at)gmail(dot)com>
To: Shubham Khanna <khannashubham1197(at)gmail(dot)com>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, Ajin Cherian <itsajin(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Enhance 'pg_createsubscriber' to retrieve databases automatically when no database is provided.
Date: 2025-03-19 05:47:23
Message-ID: CALDaNm3Os5-awMR1EkQc-HSpmvtd8zd7gYPDzRxS-qVx5AvNxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 18 Mar 2025 at 17:34, Shubham Khanna
<khannashubham1197(at)gmail(dot)com> wrote:
>
> I have added an additional test case to 040_pg_createsubscriber.pl as suggested.
>
> The attached patch contains the suggested changes.

How about we change the below code:
+# Verify that user databases (postgres, $db1, $db2) got subscriptions. Both
+# $db1 and $db2 must be escaped to pass the safe_psql(), but it is difficult.
+# Thus, we define a cursor, obtain a dbname from the instance and compere one
+# by one.
+my @user_dbs = ('postgres', $db1, $db2);
+
+my $bgconn = $node_u->background_psql('postgres');
+$bgconn->query_safe(
+ qq[
+ BEGIN;
+ DECLARE cursor CURSOR FOR SELECT datname FROM pg_subscription,
pg_database
+ WHERE subdbid = pg_database.oid and datistemplate = 'f'
+ ORDER BY pg_database.oid;
+]);
+
+# Fetch from the cursor three times and confirm the existence of the
+# subscription on $dbname
+foreach my $dbname (@user_dbs)
+{
+ my $result = $bgconn->query_safe("FETCH cursor;");
+
+ is($result, $dbname, "subscription is created on $dbname");
+}

like:
$result = $node_u->safe_psql($db1, 'SELECT datname FROM
pg_subscription, pg_database WHERE subdbid = pg_database.oid and
datistemplate = \'f\' ORDER BY pg_database.oid');
is($result, "postgres
$db1
$db2", 'subscription is created on the required databases');

I felt this might simplify your verification logic.

Regards,
Vignesh

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2025-03-19 05:50:28 Re: Fwd: [BUG]: the walsender does not update its IO statistics until it exits
Previous Message Florents Tselai 2025-03-19 05:43:41 Re: like pg_shmem_allocations, but fine-grained for DSM registry ?