pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB - Mailing list pgsql-committers

From Masahiko Sawada
Subject pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB
Date
Msg-id E1woln4-00000000gZ6-17tK@gemulon.postgresql.org
Whole thread
List 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.rupireddyforpostgres@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Ajin Cherian <itsajin@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion:
https://www.postgresql.org/message-id/CALj2ACVYYooWH-5tJ6cPKkU%2BmutVxwb_z4S%2BqAi-zdrFqxXE2Q%40mail.gmail.com
Backpatch-through: 16

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/63e7a0d2c3c7f80e52ddf216707ccc1d466453a4

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(-)


Attachment

pgsql-committers by date:

Previous
From: Dean Rasheed
Date:
Subject: pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers.
Next
From: Masahiko Sawada
Date:
Subject: pgsql: Fix logical decoding of empty prepared transactions.