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 <[email protected]> Author: Zhijie Hou <[email protected]> Reviewed-by: shveta malik <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Reviewed-by: Nisha Moond <[email protected]> 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_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1b72026d4143b55511d7fc15508819d3d750aa62 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(-)
