Re: Fix race condition in pg_get_publication_tables with concurrent DROP TABLE

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: shveta malik <shveta(dot)malik(at)gmail(dot)com>, Ajin Cherian <itsajin(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix race condition in pg_get_publication_tables with concurrent DROP TABLE
Date: 2026-07-23 18:22:01
Message-ID: CAD21AoCV09zvbbteHDxe3USKWGVSpzoRR+1SK6wWgt2=Gc5o5Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 3, 2026 at 10:27 PM Bharath Rupireddy
<bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:
>
> Hi,
>
> On Tue, Jun 30, 2026 at 10:38 AM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
> >
> > While changes to pg_get_publication_tables() look good to me,
>
> Thanks for reviewing!
>
> > I think
> > the regression tests should be implemented as an isolation test rather
> > than a TAP test in 100_bugs.pl as it can be tested without subscribers
> > and the isolation test works well for this kind of race condition
> > tests.
>
> Agreed. The isolation test avoids the extra publisher start/stop the
> TAP version needed, and it's about the same amount of code. Please
> find the attached v9 patches.

Thank you for updating the patches!

The patches look mostly good to me. I have a few minor comments:

+session s1
+# Hold an ACCESS EXCLUSIVE lock on the table in a separate session, so that
+# the pg_publication_tables query will block when it tries to open the table.
+step lock { BEGIN; LOCK pubdrop.dropme IN ACCESS EXCLUSIVE MODE; }
+# Drop the table in the lock-holding session and commit, releasing the lock.
+step drop_and_commit { DROP TABLE pubdrop.dropme; COMMIT; }

ISTM it's clearer if we write these comments to the permutation since
we might add more tests in the future that might reuse these steps.

---
+session s2
+step query
+{
+ SELECT tablename FROM pg_publication_tables
+ WHERE pubname = 'pub_all' AND schemaname = 'pubdrop'
+ ORDER BY tablename;
+}

I guess it's better to call pg_get_publication_tables() directly
instead of via pg_publication_tables. =

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2026-07-23 18:34:22 Re: [PATCH] Use ssup_datum_*_cmp for int2, oid, and oid8 sort support
Previous Message Tom Lane 2026-07-23 18:07:07 Re: POC: PLpgSQL FOREACH IN JSON ARRAY