Fix race condition in pg_get_publication_tables with concurrent DROP TABLE

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Fix race condition in pg_get_publication_tables with concurrent DROP TABLE
Date: 2026-04-22 19:31:18
Message-ID: CALj2ACVYYooWH-5tJ6cPKkU+mutVxwb_z4S+qAi-zdrFqxXE2Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I came across a race condition in pg_get_publication_tables with
concurrent DROP TABLE. pg_get_publication_tables collects table OIDs
without locks on the first call, then opens each table on later calls.
If a table is dropped in between, the function errors with "could not
open relation with OID".

This is common in environments where many tables are being created and
dropped while pg_publication_tables is queried, such as with FOR ALL
TABLES publications.

Please find the attached patch that fixes this by skipping
concurrently dropped tables instead of erroring out. Tables created
after the list is built are simply not present in the result set,
which is expected point-in-time behavior with no error. I've also
added a TAP test for this issue.

Thoughts?

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

Attachment Content-Type Size
v1-0001-Fix-race-condition-in-pg_get_publication_tables-w.patch application/x-patch 5.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul A Jungwirth 2026-04-22 19:42:41 Re: [PATCH] Fix null pointer dereference in PG19
Previous Message Tom Lane 2026-04-22 19:23:53 Re: PostgreSQL 17: Bug in libpq when libpq is dlopened/closed multiple times