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.94.2) (envelope-from ) id 1sp6sR-00GeSV-Nc for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Sep 2024 14:02:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sp6rR-003JgJ-Uk for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Sep 2024 14:01:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sp28i-00GTr1-W2 for pgsql-bugs@lists.postgresql.org; Fri, 13 Sep 2024 08:58:53 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sp28f-000wCF-It for pgsql-bugs@lists.postgresql.org; Fri, 13 Sep 2024 08:58:51 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-374bd059b12so442831f8f.1 for ; Fri, 13 Sep 2024 01:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deepbluecap-com.20230601.gappssmtp.com; s=20230601; t=1726217928; x=1726822728; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=A1DecMQs2ELjLGlMJHP9okYLeif2dLa8jHWESSWWKqM=; b=zPy109bmxYaedeM0OkhAuZMc9psUzZzego/8IAueMfIFlicgO3IHxEfgryDICw+Li4 HMmmAc1s/2pAzR6w8fGhHCn/Ce5aYVleClVQFXaTGtm7xZ1r5wzXSu7deDXn8T0FSvFj ziPzR7cb+Qs9pYAalbSJsHfWn8T2CQroTJcKtWzbvlzqAVaJ7z014JbNODhWaAspVvbv crwSbmbwCJ8GNZqUmb1MTFI/+EGw0E/mpwBBfzfjvh2GJqdRcNrkH6zKfdyu7vUIRgDw ox4d/9oVmC5iCDLxVsVMlq5L3ns1kXBBEjnyDx2PhGx5PdjnuIPqYnfSyJyjGIKtANvu FEXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726217928; x=1726822728; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A1DecMQs2ELjLGlMJHP9okYLeif2dLa8jHWESSWWKqM=; b=vul2cJEKWwpzToqNxjBB7oK6poK5V/gt9m15vBk2Y6NYBTE9OcABLKmN/bbxpHrxML cLHnDJKyUEfbfBL+Nf8oQ5frMB4xizi5kZgg50sZep5DsS1+gfNApI80t3F57afcOVCX 4LvXECt67h+WbZ9/mO2zJKiW6wYsULGqMKJ2Rink4XhyprA1x5lSLneOPe+0+1HyzVUe iJ9a7BGjFwJtNryNsubjBVVYAWCc+TUOTIKBQvG3uFDYZotDwdIvdx2eFyprDv9/TL4+ 27F2ANgMX37f71yO9ShWaI6JhCagJ5ol/B/LBSG2Sn0AX1X6D+qZjw/mXpbDAlRGFHS/ qMYQ== X-Forwarded-Encrypted: i=1; AJvYcCVpxl9wPVwmAFaqM95x/xdMW76GIRXnObz+29BTb7fAKw/2RN/3mhZ1z2cUj6Q11APHjf+D37+vQ5TX@lists.postgresql.org X-Gm-Message-State: AOJu0YyUXUwThw9aEKjJpgwJYkIiMz0VYbkj9jUOZ+8jkFyvg5l7+BFd /E5Lr+hGxiZ1TMRu/dAD25LqpDbMKAGeo2qu3CC/vWMugDMAg0CxQlvvS2gZZvk= X-Google-Smtp-Source: AGHT+IFXRDuFxyC9K2JN+QnujzXGNCfxtN0uxSINjEdeY7ChA7QYf1ac3WvfrvA0NjwTxoO0a8n0LQ== X-Received: by 2002:adf:f64c:0:b0:378:89d8:8220 with SMTP id ffacd0b85a97d-378d623b7dfmr1210990f8f.43.1726217927190; Fri, 13 Sep 2024 01:58:47 -0700 (PDT) Received: from ?IPV6:2a01:e0a:255:1000:62b5:e310:63f5:e5eb? ([2a01:e0a:255:1000:62b5:e310:63f5:e5eb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956652e8sm16513258f8f.30.2024.09.13.01.58.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Sep 2024 01:58:46 -0700 (PDT) Message-ID: Date: Fri, 13 Sep 2024 10:58:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pg_restore with --disable-triggers discards ENABLE ALWAYS To: Laurenz Albe , pgsql-bugs@lists.postgresql.org References: <78a13f951a03bf325027f8dcfb32b1b5089cdb14.camel@cybertec.at> Content-Language: en-US From: Duncan Sands In-Reply-To: <78a13f951a03bf325027f8dcfb32b1b5089cdb14.camel@cybertec.at> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Laurenz, On 12/09/2024 22:02, Laurenz Albe wrote: > On Thu, 2024-09-12 at 10:27 +0200, Duncan Sands wrote: >> CREATE TABLE test_table(x int); >> CREATE FUNCTION test_function() RETURNS trigger AS $$ BEGIN RETURN NULL; END; $$ >> LANGUAGE plpgsql; >> CREATE TRIGGER test_trigger AFTER UPDATE ON test_table FOR EACH ROW EXECUTE >> FUNCTION test_function(); >> ALTER TABLE test_table ENABLE ALWAYS TRIGGER test_trigger; >> >> Checking the table: >> >> duncan=> \d test_table >>               Table "public.test_table" >>   Column |  Type   | Collation | Nullable | Default >> --------+---------+-----------+----------+--------- >>   x      | integer |           |          | >> Triggers firing always: >>      test_trigger AFTER UPDATE ON test_table FOR EACH ROW EXECUTE FUNCTION >> test_function() >> >> ^ Observe "Triggers firing always". >> >> >> Now for the dump + restore: >> >> pg_dump -f dump.custom -Fc --table test_table >> pg_restore --data-only --disable-triggers --dbname duncan dump.custom >> >> Checking the table: >> >> duncan=> \d test_table >>               Table "public.test_table" >>   Column |  Type   | Collation | Nullable | Default >> --------+---------+-----------+----------+--------- >>   x      | integer |           |          | >> Triggers: >>      test_trigger AFTER UPDATE ON test_table FOR EACH ROW EXECUTE FUNCTION >> test_function() >> >> ^ Observe that "Triggers firing always" has disappeared. > > This looks like a user error to me. > If you restore with --data-only, the table and constraint definitions > are not restored at all. So the table "test_table" in database "duncan" > must already have existed before the restore, and the trigger was already > defined like that. No, the trigger was ENABLE ALWAYS when dumped, and restoring zapped that. To confirm that it was ENABLE ALWAYS when dumped: $ pg_restore -f - dump.custom | grep 'ENABLE ALWAYS' ALTER TABLE public.test_table ENABLE ALWAYS TRIGGER test_trigger; To summarize: the table existed before the restore, and the trigger was ENABLE ALWAYS at the moment it was dumped as shown in the steps to reproduce above: I create the table, make an ENABLE ALWAYS trigger, then dump the table, then restore the dump with --data-only and --disable-triggers. At which point (in spite of --data-only) the table has been modified: the trigger is no longer an ENABLE ALWAYS trigger. Best wishes, Duncan.