pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix crash decoding a change to a partition pending detach.
Date: Thu, 12 Nov 2026 05:58:32 +0000
Message-ID: <E1xRNpQ-00000000OvI-1oU0@gemulon.postgresql.org> (raw)

Fix crash decoding a change to a partition pending detach.

ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY leaves the partition
marked as detach-pending if its wait is interrupted by a lock timeout, a
cancel, a disconnect. Only DETACH PARTITION ... FINALIZE clears that mark.
In that state pg_class still says relispartition, while
get_partition_ancestors() already reports nothing which
get_rel_sync_entry() was not ready for. It read relispartition as meaning
that the ancestor list is not empty, and asked for its last element, which
is an assertion failure, and a NULL pointer dereference without
assertions. Decoding any change to such a partition for a FOR ALL TABLES
publication gets there, and as the change is never confirmed, a
subscription turns that into a crash loop.

Fetch the ancestors once, up front, and treat a partition with no
ancestors as a standalone table, which is how it is published once the
detach completes.

The crash is reachable since v14 (71f4c8c6f74b) for FOR ALL TABLES
publications with publish_via_partition_root, and since v19
(fd366065e06a) for any FOR ALL TABLES publication.

Author: Mikhail Nikalayeu <mihailnikalayeu@gmail.com>
Author: Zhijie Hou <houzhijie22@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Nisha Moond <nisha.moond412@gmail.com>
Discussion: https://postgr.es/m/CADzfLwWoFPT%2Ba73%3DA%3DbsNWRMZQ98NpBEMgE%3Dt1FS4O4_%3DQVLfA%40mail.gmail.com
Discussion: https://postgr.es/m/CABdArM64ZSat%3DdB094U8OCBzp1m8_Y85m6T%2BxPEgpLVJb60_rA%40mail.gmail.com
Backpatch-through: 15

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1fd94839ea873d01fa43dbc99328acd0c91e92b5

Modified Files
--------------
.../test_decoding/expected/concurrent_ddl_dml.out  | 38 ++++++++++++++++++++++
.../test_decoding/specs/concurrent_ddl_dml.spec    | 17 ++++++++++
src/backend/catalog/partition.c                    |  5 +++
src/backend/replication/pgoutput/pgoutput.c        | 20 ++++++++----
4 files changed, 74 insertions(+), 6 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1xRNpQ-00000000OvI-1oU0@gemulon.postgresql.org>
Permalink:  ../E1xRNpQ-00000000OvI-1oU0@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xRNpQ-00000000OvI-1oU0@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: akapila@postgresql.org
  Subject: Re: pgsql: Fix crash decoding a change to a partition pending detach.
  In-Reply-To: <E1xRNpQ-00000000OvI-1oU0@gemulon.postgresql.org>
  References: <E1xRNpQ-00000000OvI-1oU0@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox