agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix crash on UPDATE or DELETE of a partition pending detach.
Date: Fri, 11 Sep 2026 09:57:15 +0000
Message-ID: <E1x4y0Q-00000004Q4Y-2ga5@gemulon.postgresql.org> (raw)

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@gmail.com>
Author: shveta malik <shveta.malik@gmail.com>
Author: Nisha Moond <nisha.moond412@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Nisha Moond <nisha.moond412@gmail.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(-)



view thread (2+ messages)

Message-ID: <E1x4y0Q-00000004Q4Y-2ga5@gemulon.postgresql.org>
Permalink:  ../E1x4y0Q-00000004Q4Y-2ga5@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x4y0Q-00000004Q4Y-2ga5@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: akapila@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix crash on UPDATE or DELETE of a partition pending detach.
  In-Reply-To: <E1x4y0Q-00000004Q4Y-2ga5@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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