Re: Fix race condition in pg_get_publication_tables with concurrent DROP TABLE

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: 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-04-29 07:15:00
Message-ID: CALj2ACU29tM_SPdiW1hPtWYocvnpNfuOWXiOh1Q58cSHpYQ7zQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Tue, Apr 28, 2026 at 8:28 PM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> On Wed, Apr 29, 2026 at 7:12 AM Ajin Cherian <itsajin(at)gmail(dot)com> wrote:
>
> > One small comment. The includes need to be in alphabetical order.
> > injection_point.h should come after fmgroids.h
> >
> > +#include "utils/injection_point.h"
> > #include "utils/syscache.h"
>
> Also there is a trailing whitespace issue while applying the patch.
> Other than these, the patch looks good.

Fixed. Please find the attached v5 patch.

The fix is needed only for PG16 and later, not PG15 or PG14. The bug
was introduced by b7ae03953690 [1] in PG16, which added a table_open()
call in pg_get_publication_tables(). PG15 and earlier only use
get_rel_namespace() and syscache lookups, both of which gracefully
handle dropped relations (returning InvalidOid/false rather than
erroring).

I verified the bug and the fix on all affected branches. Please find
the attached version-specific patches for backpatching. Thank you!

[1] b7ae03953690 - Ignore dropped and generated columns from the column list

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v5-0001-PG16-Fix-pg_get_publication_tables-race-with-conc.txt text/plain 4.9 KB
v5-0001-Fix-pg_get_publication_tables-race-with-concurren.patch application/octet-stream 8.2 KB
v5-0001-PG18-Fix-pg_get_publication_tables-race-with-conc.txt text/plain 8.2 KB
v5-0001-PG17-Fix-pg_get_publication_tables-race-with-conc.txt text/plain 8.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2026-04-29 07:16:08 Re: off-by-one in pg_repack index loop
Previous Message shveta malik 2026-04-29 07:03:54 Re: Proposal: Conflict log history table for Logical Replication