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 1soqil-00EGJm-12 for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2024 20:47:20 +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 1soqij-00HAGW-3c for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2024 20:47:17 +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 1soqii-00HAG1-RM for pgsql-bugs@lists.postgresql.org; Thu, 12 Sep 2024 20:47:16 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1soqif-000r7w-Kd for pgsql-bugs@lists.postgresql.org; Thu, 12 Sep 2024 20:47:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 48CKl7pb4156699; Thu, 12 Sep 2024 16:47:07 -0400 From: Tom Lane To: Laurenz Albe cc: Duncan Sands , pgsql-bugs@lists.postgresql.org Subject: Re: pg_restore with --disable-triggers discards ENABLE ALWAYS In-reply-to: <78a13f951a03bf325027f8dcfb32b1b5089cdb14.camel@cybertec.at> References: <78a13f951a03bf325027f8dcfb32b1b5089cdb14.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Thu, 12 Sep 2024 22:02:01 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4156697.1726174027.1@sss.pgh.pa.us> Date: Thu, 12 Sep 2024 16:47:07 -0400 Message-ID: <4156698.1726174027@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Thu, 2024-09-12 at 10:27 +0200, Duncan Sands wrote: >> pg_restore --data-only --disable-triggers --dbname duncan dump.custom >> ^ 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. The given recipe seems incomplete, but I think Duncan has put his finger on a shortcoming. pg_restore with --disable-triggers will issue ALTER TABLE foo DISABLE TRIGGER ALL; and later ALTER TABLE foo ENABLE TRIGGER ALL; and if you read the fine print in the ALTER TABLE man page, you'll discover that ENABLE TRIGGER sets the triggers' replication mode to the default (origin only). I'm not sure why somebody thought that replication mode shouldn't be stored separately from enable/disable, but it isn't: there's just one four-valued state field. We could probably add code to make pg_dump individually re-enable the table's triggers with the appropriate state(s), but I can't muster too much enthusiasm for writing that myself. regards, tom lane