Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kUxYV-0002oH-CC for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Oct 2020 19:44:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kUxYT-0003L8-Dl for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Oct 2020 19:44:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kUxYT-0003L1-2L for pgsql-hackers@lists.postgresql.org; Tue, 20 Oct 2020 19:44:21 +0000 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kUxYQ-0004iw-99 for pgsql-hackers@postgresql.org; Tue, 20 Oct 2020 19:44:20 +0000 Received: by mail-io1-xd44.google.com with SMTP id y20so63374iod.5 for ; Tue, 20 Oct 2020 12:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=07EcHfFvRce26Oo8rX2Ww6ZQgxUkQiYODBmR1C/4bDM=; b=xD/ZNsgFOecJuSsputq3T7rJYK8goAfodw+GBcriBB2SxFoMUozU6jzsNCd6BazfZ9 sQVNcFJyBMkG2orrFVdpKgvhAP1/KdJMtKe6MxcAjL2O92MbBNVx5D3fUGa30oR5j7Ns DUcFO/YA3tLoePmtoVuamqQDOIJz1PyI3AIXuDKi6IRHnQ9ElU/CZXht39VCAVPokRxg skmte6QwQq6R6hgv6w17uPX+b305vN7SoE2i2PjfS8jqxGDg4SIQQ/IqIwZE+Lb1oBy5 /PDdkzt4BsGQgjpnZX3bJybRzEYS+MlTx6RAtBWBjw6JiPD8RCSK4dHF4r9C1SweDAQg P1rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=07EcHfFvRce26Oo8rX2Ww6ZQgxUkQiYODBmR1C/4bDM=; b=nptyibL1o5c8exZlhs/Hz8puTB+kvRWTFulVqEn9phqSE6Kub2jzFVlQuFkd3rxUHS uRr8s8XR3tMAsBxbM+2lYkP1N67MVviTv+WWe9KSXmiZmjOuz7jicBtjk72j7xMUCbca HL29zO5pbsIYSKy8457PnyRBsOeMNRN9+Hxo9VTULOOQQU+a5/sOAvnSr0gE+47+WNke 7rFH10FWzIEj3tJ52HSAzopv/Owjz3129PRHsAyb2cOJKE+dWnSFgC0isx8FpPklYdt/ m/p8ZC1zhDAuTwnVcK3EEkzmGrFaoUKkeWa7JXc7YVAa0wZXO71SVLuz6fU/CehedsZ/ D/Fw== X-Gm-Message-State: AOAM532gtcst1zjOFN3D+Cuk90WwYc5KnkuJeYXNaFKCLvHu8iB/hqAG AwdFQTA49SAF0GOmv2WqOO4TSw== X-Google-Smtp-Source: ABdhPJws+RoN4kJRx+ATUv9R/oMAh/GyexOyZ3GFTxAyFUu1FCEi90H4DEQuKTpLyfdRCHZTsHE+VA== X-Received: by 2002:a5d:8b4c:: with SMTP id c12mr3407665iot.167.1603223056263; Tue, 20 Oct 2020 12:44:16 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b14sm3104494ilg.63.2020.10.20.12.44.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Oct 2020 12:44:15 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id DF92B800740; Tue, 20 Oct 2020 14:44:12 -0500 (CDT) Date: Tue, 20 Oct 2020 14:44:12 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: pgsql-hackers@postgresql.org, Amit Langote Subject: Re: CREATE TABLE .. PARTITION OF fails to preserve tgenabled for inherited row triggers Message-ID: <20201020194412.GF9241@telsasoft.com> References: <20200930223450.GA14848@telsasoft.com> <20201020190420.GA18579@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201020190420.GA18579@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Oct 20, 2020 at 04:04:20PM -0300, Alvaro Herrera wrote: > On 2020-Sep-30, Justin Pryzby wrote: > > > CREATE TABLE t(i int) PARTITION BY RANGE(i); > > CREATE TABLE t1 PARTITION OF t FOR VALUES FROM (1) TO (10); > > CREATE OR REPLACE FUNCTION tgf() RETURNS trigger LANGUAGE plpgsql AS $$ begin raise exception 'except'; end $$; > > CREATE TRIGGER tg AFTER INSERT ON t FOR EACH ROW EXECUTE FUNCTION tgf(); > > ALTER TABLE t1 DISABLE TRIGGER tg; > > INSERT INTO t VALUES(1); -- inserts when trigger is disabled: good > > ALTER TABLE t DISABLE TRIGGER tg; > > CREATE TABLE t2 PARTITION OF t FOR VALUES FROM (10) TO (20); > > > > postgres=# SELECT tgrelid::regclass, tgenabled FROM pg_trigger WHERE tgrelid::regclass::text IN ('t1','t2'); > > tgrelid | tgenabled > > ---------+----------- > > t1 | D > > t2 | O > > (2 rows) > > > > I consider this a bug,but CreateTrigStmt doesn't have any "enabled" member > > (since it's impossible to CREATE TRIGGER .. DISABLED), so I'm not sure where > > the fix should be. > > Hmm, next question: should we backpatch a fix for this? (This applies > all the way back to 11.) If we do, then we would change behavior of > partition creation. It's hard to see that the current behavior is > desirable ... and I think anybody who would have come across this, would > wish it behaved the other way. But still -- it would definitely be a > behavior change. +0.8 to backpatch. To v13 if not further. We don't normally disable triggers, otherwise I would say +1. For context, I ran into this issue while migrating a customer to a new server using pg_restore and a custom backup script which loops around pg_dump, and handles partitioned tables differently depending if they're recent or historic. Our backup job works well, but is technically a bit of a hack. It doesn't do the right thing (causes sql errors and pg_restore warnings) for inherited indexes and, apparently, triggers. Disabling the trigger was my 4th attempt to handle an error restoring a specific table (mismatched column type between parent dump and child dumped several days earlier). I eventually (5th or 6th attempt) dropped the parent trigger, created the child tables using --section=pre-data, ALTERed a column to match, and then ran post-data and attached it. -- Justin