| From: | Masahiko Sawada <msawada(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB |
| Date: | 2026-07-28 17:40:39 |
| Message-ID: | E1wolnD-00000000gaT-1w3g@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Fix pg_get_publication_tables() failure with concurrent DROP TABLE.
pg_get_publication_tables() collects the OIDs of the published tables
on its first call, without locking them, and then reopens each table
later, once per result row, to compute its column list and fetch its
row filter. The reopen used table_open(), which errors out with "could
not open relation with OID" if the table has been dropped in the
meantime. This could happen for any published table without an
explicit column list, which is every table in FOR ALL TABLES and FOR
TABLES IN SCHEMA publications, but also FOR TABLE entries without a
column list. The failure is common in environments where many tables
are created and dropped while publication tables are being queried,
e.g. by table synchronization on a subscriber.
Fix by opening every table with try_table_open(), which returns NULL
if the relation no longer exists, and skipping the table in that
case. Concurrently dropped tables are thus simply absent from the
result set, which is the expected point-in-time behavior.
As a side effect, tables with an explicit column list, which were
previously returned without being opened, are now also locked with
AccessShareLock, so the function can block behind concurrent DDL on
such tables where it previously did not.
Backpatch to v16, where we added the table_open() call in
pg_get_publication_tables().
Author: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Reviewed-by: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Reviewed-by: Ajin Cherian <itsajin(at)gmail(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/CALj2ACVYYooWH-5tJ6cPKkU%2BmutVxwb_z4S%2BqAi-zdrFqxXE2Q%40mail.gmail.com
Backpatch-through: 16
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/73d63d1c1f676f4fcb289cdf9d052881719eb02f
Modified Files
--------------
src/backend/catalog/pg_publication.c | 52 ++++++++++++++++++----
.../isolation/expected/pub-concurrent-drop.out | 16 +++++++
src/test/isolation/isolation_schedule | 1 +
src/test/isolation/specs/pub-concurrent-drop.spec | 36 +++++++++++++++
src/tools/pgindent/typedefs.list | 1 +
5 files changed, 97 insertions(+), 9 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Masahiko Sawada | 2026-07-28 17:40:44 | pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB |
| Previous Message | Masahiko Sawada | 2026-07-28 17:40:34 | pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB |