pgsql: Fix crash in subscription refresh on concurrent relation drop.

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix crash in subscription refresh on concurrent relation drop.
Date: 2026-08-26 19:06:03
Message-ID: E1wzIwk-00000002EGR-1Zql@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix crash in subscription refresh on concurrent relation drop.

Commit 46b4f5c11b0 made the logical replication origin checks quote
the schema and relation names they interpolate into the query sent to
the publisher. Those names can be NULL, which that commit overlooked.

AlterSubscription_refresh() collects the OIDs of the relations already
present in pg_subscription_rel and hands them to
check_publications_origin_tables() and
check_publications_origin_sequences(), which append the
schema-qualified name of each one to the query so that
already-subscribed relations are excluded from the check. The
relations are never locked, so one of them can be dropped concurrently
before its name is read, and get_rel_name() and get_namespace_name()
return NULL. quote_literal_cstr() dereferences it and crashes the
backend.

This commit fixes this by skipping a relation whose name is no longer
available. A dropped relation is not synchronized anyway, and the
appended clauses only exclude relations from a check whose sole effect
is a WARNING, so omitting one can at most produce a spurious WARNING.

The window is reachable from ALTER SUBSCRIPTION ... REFRESH
PUBLICATION and from SET, ADD and DROP PUBLICATION, which refresh by
default, but only when copy_data is true and origin is none. Backpatch
to v16 as commit 46b4f5c11b0 was back-patched that far. The sequence
path exists only in v19 and later.

The test is applied to v19 and later only. Adding it to v17 and v18
would require enabling injection point support in
src/test/subscription there, and v16 predates injection points
entirely. That is more test infrastructure churn on stable branches
than this fix warrants.

Reported-by: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>
Author: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>
Co-authored-by: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Reviewed-by: Ajin Cherian <itsajin(at)gmail(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAHg+QDcd_o3707Ey8c8b7HkE-t14g8c0tk8ME3ctywDsh3ut8g@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_18_STABLE

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

Modified Files
--------------
src/backend/commands/subscriptioncmds.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2026-08-26 19:06:07 pgsql: Fix crash in subscription refresh on concurrent relation drop.
Previous Message Masahiko Sawada 2026-08-26 19:05:59 pgsql: Fix crash in subscription refresh on concurrent relation drop.