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 <[email protected]>
Author: shveta malik <[email protected]>
Author: Nisha Moond <[email protected]>
Reviewed-by: shveta malik <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Zhijie Hou <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Reviewed-by: Nisha Moond <[email protected]>
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(-)

Reply via email to