Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2WNy-0001Nx-Lq for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2019 07:59:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i2WNx-0002Cs-Cy for pgsql-general@arkaria.postgresql.org; Tue, 27 Aug 2019 07:59:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2WNw-0002BU-UM for pgsql-general@lists.postgresql.org; Tue, 27 Aug 2019 07:59:25 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2WNv-0006SS-BD for pgsql-general@postgresql.org; Tue, 27 Aug 2019 07:59:24 +0000 Received: by mail-wm1-x344.google.com with SMTP id l2so1962540wmg.0 for ; Tue, 27 Aug 2019 00:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=9oqVlf7Ir6qYuNs6g7h8IqoZCPqSVPCueT8wEBSi7HI=; b=fGH0ihWSzCfqtqSJx5+JCyGRXl1+ZEzlA+HrNHmhHtaVfpePr5jNxv/mHqzwMNXwQj 23KaFKnpZn5MQMVYYLrsM9YnJXeo+OujwD5EcG5myahr/u3eidTZIYM3jVBkHRaCnrZm i8gD876prpDL5K2zARvEDLSoWqVsxG9lJFoQLFjz/JcPX0LZoym9/kkcavBDZFsEqJi7 Ei218ZptrljcQVXebhFWqft5m5pzGEHk/R268IHGoh5oExRMrDw0jgZjJQXTM4zHt1x3 eQLQ2pQDOTLE5SJw06xL+vehir0AF6ADJ54JkI8gOAQdMt8my5Un8iC0FtMQFu6XTmzg jhhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=9oqVlf7Ir6qYuNs6g7h8IqoZCPqSVPCueT8wEBSi7HI=; b=UCe70iyUdzx4r1tuS4KjHbB8tWoS+/NzF2RDTXpGInlojd0cVG05ylBKvUxRED67GT AUVcK/wNGmdoFZfQkBhT/+iHSK9Oub5RuvZn165jBXk7t3Oqm+/QEMcreiaQLW+20Hvm cbQQ/0/haJMpv1cjwKF4WYryELnIANJlpMEn9hAbppQU/HJ8+2gdW6lCcTvxCLcdX1kZ L/XipAEA7dtzefPm68sXM+m/NRQ7NM5xzjn/zQ7k8btPi+U7bCoqFmp8lTHANiRktzsu q3F6fox1u6iOZy2I+bOfht6/U2pfVwyWDgxWix7pbRCBBxMeF/s7e4fHBHwrq0Au1Hkj H3VQ== X-Gm-Message-State: APjAAAXnIuhmNK3+5BclmzeEHfxb9IatREpgAss9+YPInlhKG3X+IFcc MtFsRzoO/dWb4txilO7gU6J/5g== X-Google-Smtp-Source: APXvYqyIeSkQYNfsdAONArouPhBdDG7P6n182McGbziA1bjkWDSztanCNO4VjQFivjNMkrfKftYnPg== X-Received: by 2002:a1c:4d0c:: with SMTP id o12mr27438355wmh.62.1566892762221; Tue, 27 Aug 2019 00:59:22 -0700 (PDT) Received: from localhost.localdomain ([212.186.219.234]) by smtp.gmail.com with ESMTPSA id p19sm1692749wmg.31.2019.08.27.00.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2019 00:59:21 -0700 (PDT) Message-ID: <5af9d5d6ce2c3fa1d86aa755fe880044f0b1f098.camel@cybertec.at> Subject: Re: cannot CREATE INDEX because it has pending trigger events From: Laurenz Albe To: Simon Kissane , pgsql-general@postgresql.org Date: Tue, 27 Aug 2019 09:59:20 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 2019-08-27 at 12:00 +1000, Simon Kissane wrote: > We have an application that works fine with Postgres 9.6, but fails > with this error when we try installing it against 11.5 > > I simplified the problem down to the following reproduce script: > > BEGIN TRANSACTION; > CREATE TABLE resource (resource_id BIGINT NOT NULL PRIMARY KEY, > resource_type BIGINT NOT NULL); > ALTER TABLE ONLY resource ADD CONSTRAINT resource_type_fk FOREIGN KEY > (resource_type) REFERENCES resource (resource_id) DEFERRABLE > INITIALLY DEFERRED; > INSERT INTO resource (resource_id,resource_type) values (1,1); > INSERT INTO resource (resource_id,resource_type) values (2,1); > INSERT INTO resource (resource_id,resource_type) values (3,2); > CREATE UNIQUE INDEX IF NOT EXISTS resource_type_2_singleton ON > resource (resource_type) WHERE resource_type=2; > COMMIT; > > That script works fine in Postgres 9.6, but run it against 11.5 you > get the error: > > ERROR: cannot CREATE INDEX "resource" because it has pending trigger > events > STATEMENT: CREATE UNIQUE INDEX IF NOT EXISTS > resource_type_2_singleton ON resource (resource_type) WHERE > resource_type=2; This is fallout of commit 0d1885266630: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=0d1885266630eee1de5c43af463fe2b921451932 This commit is the fix for a bug: https://www.postgresql.org/message-id/flat/A737B7A37273E048B164557ADEF4A58B53A4DC9A%40ntex2010i.host.magwien.gv.at This might be a false positive hit or not, I am not certain. Maybe the check is not required for AFTER triggers. Anyway, the problem can be avoided by running SET CONSTRAINTS resource_type_fk IMMEDIATE; right before the CREATE INDEX, so I don't think it is a real problem. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com