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 1xKANm-00000000gwX-2hPn for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Oct 2026 08:12:11 +0000 Received: from localhost ([127.0.0.1]:35978 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xKANm-0000000F6ms-0pCI for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Oct 2026 08:12:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJtQl-0000000C9LT-2hHr for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:06:07 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJtQj-00000000QLQ-2mi3 for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:06:07 +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=ki0dkZ0zNYqDl3A8LKwsBX7Xk5IFW16L1TbqToERg1s=; b=lTRSAuCCvoopNlWMefiisVGQgl Mhmd/uOjSj8WM4wzJxcyYEvgPlAWohOnFf0bB8QQ/CFOqXrEFVcJAf59P2CNaidfwFjhn4L7Fuyef ojog9NxKKllXgfJgu+FU1kW7NEf+wRO4dH97A2AONxDFWAd8TOHynuc2zSlKtpCdMdbNzY6LZmxDN mKE8Pq1F/SIYvknm0KCq0XTBK64PIwDlgxFcrPhzVkx9BCJIil+B+njTTyoOUZFa1TNNtuRUDn8+E ZZb8MhG0MfQnrYWTSawoDwnq3nhCxCWax6rNOBfCDWS7ZMzuFlLInQqpM8BhSDt+UEwNIB4/Zu1Xo UdopD6vg==; 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 1xJtQi-000000016DO-1uX2 for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:06: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 1xJtQh-000000035Cx-1oGm for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 14:06:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19790: "cannot start a subtransaction ... inval messages" after "ALTER DOMAIN ... DROP CONSTRAINT" To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: alpkeles99@gmail.com Reply-To: alpkeles99@gmail.com, pgsql-bugs@lists.postgresql.org Date: Thu, 22 Oct 2026 14:05:57 +0000 Message-ID: <19790-fda013085342fe7f@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: 19790 Logged by: Alperen Keles Email address: alpkeles99@gmail.com PostgreSQL version: 18.6 Operating system: macOS 26 arm64 Description: =20 Hello, After ALTER DOMAIN ... DROP CONSTRAINT inside a transaction, the next subtransaction that changes the catalogs fails with an internal error: CREATE DOMAIN d AS int CHECK (VALUE > 0); BEGIN; ALTER DOMAIN d DROP CONSTRAINT d_check; SAVEPOINT s; CREATE TABLE x (a int); ERROR: cannot start a subtransaction when there are unprocessed inval messages The same happens with a PL/pgSQL block with an EXCEPTION clause. Here the ADD CONSTRAINT should fail validation with check_violation and be caught; instead the XX000 error escapes the handler and aborts the transaction: CREATE DOMAIN d2 AS int2 CONSTRAINT d2_k CHECK (VALUE IS NOT NULL); CREATE TABLE t1 (c0 d2); INSERT INTO t1 VALUES (-512); BEGIN; ALTER DOMAIN d2 DROP CONSTRAINT d2_k; DO $$BEGIN ALTER DOMAIN d2 ADD CONSTRAINT d2_k CHECK (VALUE >=3D -303); EXCEPTION WHEN check_violation THEN RAISE NOTICE 'caught'; END$$; ERROR: cannot start a subtransaction when there are unprocessed inval messages CONTEXT: SQL statement "ALTER DOMAIN d2 ADD CONSTRAINT d2_k CHECK (VALUE >=3D -303)" It also happens with DROP CONSTRAINT IF EXISTS of a constraint that does not exist, with a domain NOT NULL constraint, when a plain SELECT runs between the DROP and the SAVEPOINT, and inside a single DO block outside a transaction block (DROP, then an inner BEGIN ... EXCEPTION block). It does not happen if the subtransaction changes no catalogs, if another catalog-changing statement runs at the top level between the DROP and the SAVEPOINT, or after ALTER DOMAIN ... ADD CONSTRAINT instead of DROP. Nothing is logged besides the error; after ROLLBACK the session works normally. Reproduced on 18.6 (REL_18_STABLE a85b5523e67) and master 158b6d5109f, macOS arm64, --enable-cassert. The first failing commit is 3aafc030a53 ("Reduce memory consumption for pending invalidation messages"), which added this check; its parent works. As far as I can tell: AlterDomainDropConstraint() calls performDeletion(), whose deleteOneObject() ends with CommandCounterIncrement(), and only afterwards queues CacheInvalidateHeapTuple() for the domain's pg_type row. That writes nothing, so the command ID is not marked used, and the CommandCounterIncrement() at the end of the statement does nothing. The message stays in the top level's CurrentCmdInvalidMsgs until the next subtransaction registers its own message, and PrepareInvalidationState() raises the error. Found with a query fuzzer. Regards, Alperen Keles