Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTNvf-00000000IVr-2LJd for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 18:29:16 +0000 Received: from localhost ([127.0.0.1]:56772 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTNve-00000006ZFm-3x1n for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 18:29:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:36884) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTKhD-00000005lAb-2AI7 for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 15:02:07 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTKhA-00000000ABT-1fa3 for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 15:02:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=sQ83MBSk4ZgdqUxSKtXMpclqYFG++TCBkj3xqWytIjI=; b=MQkwIlxM9GrHj6Z+vvBNx6uyVp dX2zkjRYm/EntohpBEn1mTz585V3YLaK25mbVTMMDn3jE9r3FK6YKyzgbYTPwETrkaDF9kDDntMyO Dxd4VKKNycMPHwYAg6lohSJb8E0JMXhIy68dWdR44lTnjV4eUHtI0Pe1RZgBAbR0Jn4d9ptp3qrPB 2f5+n1eH4r6i5c3zj7v49bEkObUeAyibzmYy3ei43IF8gPtOJgsqP5XJ5NOzHI18koKt5TgI3PDfE 8f1EqLL1zZfqNtD0innV2zNQkx+6OKDv6DOvrWKWEFC1XvRwGUkIf4Qfq7kNMivs3wVQicH3kDT0u dJXlhhDQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTKhA-00000000TJG-0OPu for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 15:02:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTKh9-00000001ASB-0SSv for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 15:02:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19913: Parent ALTER TABLE during concurrent DETACH leaves pending partition unusable (42804) To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Tue, 17 Nov 2026 15:01:50 +0000 Message-ID: <19913-ee9177a3015ae4be@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19913 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: Unsupported/Unknown Operating system: Linux x86_64; master build 81b2179b492 (20devel) Description: =20 **PostgreSQL version:** 20devel master build (commit 81b2179b492, built 2026-10-27). DETACH PARTITION ... CONCURRENTLY and the detach-pending state (pg_inherits.inhdetachpending) exist since PG14, so supported versions may be affected as well; I have not verified on a release build. **Operating system:** Linux x86_64 **Description:** If ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY is cancelled while waiting for a lock, the partition is intentionally left in a "detach pending" state (pg_inherits.inhdetachpending =3D true), to be finished later with ALTER TABLE ... DETACH PARTITION ... FINALIZE. That recovery works fine =C3=A2=C2=80=C2=94 unless, while the partition is pending, certain ALTER TA= BLE operations are run on the partitioned parent. Concretely, ALTER TABLE ... ADD COLUMN on the parent silently skips the pending partition, while that partition still retains its partition bound. From that point on: - INSERT and UPDATE on the partition fail with 42804 "could not convert row type" - pg_get_partition_constraintdef() on the partition fails with the same error - ALTER TABLE ... DETACH PARTITION ... FINALIZE itself fails with the same 42804, so the detach can never be completed - a plain DETACH is rejected with 55000 ("cannot detach partition ... already pending detach") The only recovery I found is DROP TABLE on the partition. A control run with the same pending state but no parent DDL finalizes normally, so the pending state itself is recoverable; it is the parent-side ALTER that breaks it. **Reproduction (three sessions, READ COMMITTED):** Setup: ```sql CREATE TABLE g (val int, data int) PARTITION BY LIST (val); CREATE TABLE p1 PARTITION OF g FOR VALUES IN (1); CREATE TABLE p2 PARTITION OF g FOR VALUES IN (2); INSERT INTO g VALUES (1, 111), (2, 222); ``` Session 1 (holds a lock, does not commit): ```sql BEGIN; SELECT * FROM g; ``` Session 2 (blocks waiting for session 1): ```sql ALTER TABLE g DETACH PARTITION p1 CONCURRENTLY; ``` Session 3 (waits until the partition is pending, cancels session 2, lets session 1 commit): ```sql -- wait until this returns true: SELECT inhdetachpending FROM pg_inherits WHERE inhrelid=3D'p1'::regclass; SELECT pg_cancel_backend(); -- then in session 1: COMMIT; ``` The problem: a parent-side ALTER TABLE while p1 is pending, in a fresh session: ```sql ALTER TABLE g ADD COLUMN extra int; ``` Observed afterwards: ```text INSERT INTO p1 VALUES (1, 999); -- ERROR 42804: could not convert row type UPDATE p1 SET data =3D 888 WHERE val =3D 1; -- ERROR 42804: coul= d not convert row type SELECT pg_get_partition_constraintdef('p1'::regclass); -- ERROR 42804: could not convert row type ALTER TABLE g DETACH PARTITION p1 FINALIZE; -- ERROR 42804: could not convert row type ALTER TABLE g DETACH PARTITION p1; -- ERROR 55000: cannot detach partition "p1" DROP TABLE p1; -- OK (only recovery found) ``` The catalog state before the DROP still shows p1 as a partition: relispartition =3D true, inhdetachpending =3D true, relpartbound set. Control: the same three-session construction without any parent DDL during the pending window =C3=A2=C2=80=C2=94 INSERT, UPDATE and DETACH ... FINALIZ= E all succeed, and the partition ends up properly detached. Variants, same construction with a different parent DDL during the pending window: - ALTER TABLE g DROP COLUMN data; =C3=A2=C2=80=C2=94 does not break the par= tition; everything including FINALIZE still works. - ALTER TABLE g ALTER COLUMN data TYPE bigint; =C3=A2=C2=80=C2=94 behaves l= ike ADD COLUMN: INSERT/UPDATE/pg_get_partition_constraintdef and DETACH FINALIZE all fail with 42804, plain DETACH 55000, only DROP TABLE recovers. So parent row-type changes that alter the shared column layout in one direction break the pending partition, while DROP COLUMN does not. **Root cause (analysis):** Parent-side ALTER TABLE recursion over the partitions skips partitions in detach-pending state (find_inheritance_children with the omit-detached option =C3=A2=C2=80=C2=94 presumably deliberate, to not touch a partition t= hat is being detached). But the pending partition still has its partition bound set and is still treated as an attached partition by code paths that convert tuples between the partition's row type and the parent's (now changed) row type. Those conversions fail with "could not convert row type", and DETACH ... FINALIZE hits the same conversion when it tries to finish the detach, which makes the pending state unrecoverable except by dropping the partition.