agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB
5+ messages / 1 participants
[nested] [flat]

* pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB
@ 2026-07-28 17:40 Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Masahiko Sawada @ 2026-07-28 17:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB
@ 2026-07-28 17:40 Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Masahiko Sawada @ 2026-07-28 17:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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...
Backpatch-through: 16

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/28c995948cfd6b8ff3b2576aedd6f3d38107e9bc

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB
@ 2026-07-28 17:40 Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Masahiko Sawada @ 2026-07-28 17:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB
@ 2026-07-28 17:40 Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Masahiko Sawada @ 2026-07-28 17:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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...
Backpatch-through: 16

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/dcbc96685dc5483c9e723e7380e02edb3c9ec7a3

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB
@ 2026-07-28 17:40 Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Masahiko Sawada @ 2026-07-28 17:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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...
Backpatch-through: 16

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6c760f6b6a3a8c1c49cdc54be62363af4308d62c

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-07-28 17:40 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-28 17:40 pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB Masahiko Sawada <msawada@postgresql.org>
2026-07-28 17:40 pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB Masahiko Sawada <msawada@postgresql.org>
2026-07-28 17:40 pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB Masahiko Sawada <msawada@postgresql.org>
2026-07-28 17:40 pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB Masahiko Sawada <msawada@postgresql.org>
2026-07-28 17:40 pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB Masahiko Sawada <msawada@postgresql.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox