Renaming a partitioned table's trigger skips a partition pending DETACH CONCURRENTLY; pg_dump re-attaches it and restore or pg_upgrade fails on the stale clone name ==================================================================================================================================================================== AI-generated bug report from the AI Annex Report ID: 01a22b24-b2bd-7921-a4b3-9a44ee1eeba7 Filed: 2026-11-30 06:29:15 UTC Severity: 30/100 Blamed commit: 71f4c8c6f74ba021e55d35b1128d22fb8c6e1629 ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY leaves the partition marked inhdetachpending when its wait is interrupted (lock timeout, cancel). Until DETACH ... FINALIZE runs, the partition keeps the cloned row triggers of its parent, with tgparentid still set. ALTER TRIGGER ... RENAME on the parent recurses through RelationGetPartitionDesc(rel, true), which omits detach-pending partitions. The pending partition's clone keeps the old name. pg_dump does not look at inhdetachpending and emits a plain ALTER TABLE ... ATTACH PARTITION for the pending partition. On restore, ATTACH clones the parent's trigger under its new name, and the dumped ALTER TABLE ... ENABLE ALWAYS TRIGGER for the clone fails. CREATE FUNCTION f() RETURNS trigger LANGUAGE plpgsql AS $$BEGIN RETURN NEW; END$$; CREATE TABLE r (k int, a int) PARTITION BY LIST (k); CREATE TABLE r1 PARTITION OF r FOR VALUES IN (1); CREATE TABLE r9 PARTITION OF r FOR VALUES IN (9); CREATE TRIGGER audit AFTER INSERT ON r FOR EACH ROW EXECUTE FUNCTION f(); ALTER TABLE r9 ENABLE ALWAYS TRIGGER audit; -- session 1 BEGIN ISOLATION LEVEL REPEATABLE READ; SELECT count(*) FROM r; -- session 2 SET statement_timeout = '1s'; ALTER TABLE r DETACH PARTITION r9 CONCURRENTLY; -- ERROR: canceling statement due to statement timeout -- session 1 COMMIT; ALTER TRIGGER audit ON r RENAME TO audit2; -- r9 still has clone "audit" (tgenabled A, tgparentid set) pg_dump output contains: ALTER TABLE ONLY public.r ATTACH PARTITION public.r9 FOR VALUES IN (9); CREATE TRIGGER audit2 AFTER INSERT ON public.r ...; ALTER TABLE public.r9 ENABLE ALWAYS TRIGGER audit; Restoring it (plain or -Fc) gives: ERROR: trigger "audit" for table "r9" does not exist and r9 ends up attached with trigger audit2 in state O, so the partition's ENABLE ALWAYS setting is lost. A same-version pg_upgrade of the cluster fails at "Restoring database schemas in the new cluster" with the same error. Other parent-level trigger DDL also skips the pending partition (CREATE TRIGGER, ENABLE/DISABLE TRIGGER), and the re-attach in the dump then silently gives the partition triggers and states it did not have. Only RENAME was found to break the restore. Either pg_dump should not emit ATTACH PARTITION for a detach-pending partition (dump it as detached, with no cloned triggers, matching what FINALIZE would leave), or the trigger DDL recursion should include detach-pending partitions. Tested on master at 03dd453a67cfb37e440f998eb1a61b643e037591. Notes: - Branches: master (reproduced at 03dd453a67cf); REL_15 through REL_19 likely by code inspection (renametrig_partition recursion present, no inhdetachpending handling in pg_dump). REL_14 has the pending-detach state and the same pg_dump behavior but no ALTER TRIGGER RENAME recursion, so this exact path does not apply there. - Blame: 71f4c8c6f74b introduced the detach-pending state without pg_dump support; 80ba4bb38353 added the RENAME recursion through RelationGetPartitionDesc(..., true). - Related: same root cause as pgsql-bugs BUG #19100 (ALTER TYPE on the parent skips the pending partition; that thread suggests pg_dump should not emit ATTACH for detach-pending tables).