pgsql: Fix crash on UPDATE or DELETE of a partition pending detach.

From: Amit Kapila <akapila(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix crash on UPDATE or DELETE of a partition pending detach.
Date: 2026-09-11 09:57:15
Message-ID: E1x4y0Q-00000004Q4Y-2ga5@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix crash on UPDATE or DELETE of a partition pending detach.

ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY leaves the partition
marked as detach-pending if its wait is interrupted, and only DETACH
PARTITION ... FINALIZE clears that mark. In that state pg_class still says
relispartition while get_partition_ancestors() already reports nothing,
which RelationBuildPublicationDesc() was not ready for. It took
relispartition to mean that the ancestor list is not empty and asked for
its last element, which is an assertion failure, or a NULL pointer
dereference without assertions. CheckCmdReplicaIdentity() needs the
descriptor for every UPDATE and DELETE of a publishable relation and
builds it on first use, so no publication has to exist for this, and a
plain UPDATE crashes the backend.

Treat such a partition as a standalone table, as after the detach is
finalized. It is then published by FOR ALL TABLES publications, but cannot
be added to an EXCEPT clause until the detach completes, which is now
reported with a hint to run DETACH PARTITION ... FINALIZE.

Oversight in fd366065e06a, which added the exclusion.

Author: Mikhail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Author: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Author: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>
Reviewed-by: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Reviewed-by: Zhijie Hou <houzj(dot)fnst(at)fujitsu(dot)com>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Reviewed-by: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>
Discussion: https://postgr.es/m/CADzfLwWoFPT%2Ba73%3DA%3DbsNWRMZQ98NpBEMgE%3Dt1FS4O4_%3DQVLfA%40mail.gmail.com
Backpatch-through: 19, where it was introduced

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/090b44557d45686403d2d98c32d1d3add4337361

Modified Files
--------------
src/backend/catalog/pg_publication.c | 9 ++++++++
src/backend/utils/cache/relcache.c | 10 ++++++++-
.../expected/detach-partition-concurrently-3.out | 25 ++++++++++++++++++++++
.../specs/detach-partition-concurrently-3.spec | 10 +++++++++
4 files changed, 53 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2026-09-11 11:44:35 pgsql: Disallow REPACK (CONCURRENTLY) when replica identity index is dr
Previous Message Fujii Masao 2026-09-11 09:17:16 pgsql: psql: Schema-qualify catalogs in ALTER DATABASE RESET completion