Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyJGp-0004VH-55 for pgsql-general@arkaria.postgresql.org; Tue, 20 Mar 2018 15:33:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eyJGo-0003BF-3b for pgsql-general@arkaria.postgresql.org; Tue, 20 Mar 2018 15:33:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyJGn-0003B5-Ox for pgsql-general@lists.postgresql.org; Tue, 20 Mar 2018 15:33:49 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyJGk-0001ND-F0 for pgsql-general@postgresql.org; Tue, 20 Mar 2018 15:33:48 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 756D0215C6; Tue, 20 Mar 2018 11:33:45 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Tue, 20 Mar 2018 11:33:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=EEy9igaEluNWqNXpkujLts1AjhCT0 1gOkCxuTExnleY=; b=Hu1kXzdfinbXA8SpWZ7XLDo7JhxeWCUlDiw38rWwYTGLM 1rAkjAgqtsurc7L0dZTTB6ui6ZfWGY8reWEh9iBiYpncerkv5fehbAkwiebutiLS 3pz8ONm9I0R0lzgd65yCwtr25EqagSogoDpOfZtDXGEeZ0MJeoEp+Pyya4YXlb+V Z0f8vjry1/ut9BYfPOxfwgDWdpPS8xxVptSm5ihEgIM+mhtdL+IQnXrL7lbGouPQ fU0EbksVrdhyPajer269Ewq6wcw7kphHQ3nz830bG5YVebXT1h0vnwoElex4htpX Gri76zAyvrxJ3F3D7TP/kpcuVVBgkaA2FnxgMwg+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=EEy9ig aEluNWqNXpkujLts1AjhCT01gOkCxuTExnleY=; b=RHUB/yfCEZ9Ui84kOJf1fj yw3iYNkyHfRBo0G7Qwq7aa9IHeAR7Ang2JwfxuMNcg83aEKr7ii1wSL4aKAlWQVB aoF6vWmeiYTRtx2m6U/Svny5ePKlzNxrPZSEPAfS1ubafrSxrT4VsD5ZdLpQyqQg fHi8WhMssWg6hXVvnsYNnO6PLrIdoq2p74HWMimZvbM+FlefMmq2ZeS8ECGydQGY ppAhpgNZVgY/D8TovCHpUC6/AyyXAaO5p4Npci+VyYvKl/eer9O7LGENl7Xfm309 a+1u9hfSq+z7cdqdaBnBQ8CYpX+M19yFhJHu9BUndgKW2tOTk1Y2lbLM8nt2DGTA == X-ME-Sender: Received: from [192.168.1.2] (71-35-123-124.tukw.qwest.net [71.35.123.124]) by mail.messagingengine.com (Postfix) with ESMTPA id C6AFC241D8; Tue, 20 Mar 2018 11:33:44 -0400 (EDT) Subject: Re: Restore - disable triggers - when they fired? To: Durumdara Cc: Postgres General References: From: Adrian Klaver Message-ID: Date: Tue, 20 Mar 2018 08:33:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/20/2018 07:56 AM, Durumdara wrote: > Dear Adrian! > > > 2018-03-20 15:47 GMT+01:00 Adrian Klaver >: > > > > When it would be useful? > > > https://www.postgresql.org/docs/10/static/app-pgrestore.html > > "--disable-triggers > >     This option is relevant only when performing a data-only > restore. It instructs pg_restore to execute commands to temporarily > disable triggers on the target tables while the data is reloaded. > Use this if you have referential integrity checks or other triggers > on the tables that you do not want to invoke during data reload. > >     Presently, the commands emitted for --disable-triggers must be > done as superuser. So you should also specify a superuser name with > -S or, preferably, run pg_restore as a PostgreSQL superuser. > > > > > Firstly I supposed that data copy somehow could start the > triggers - but how? > > Which triggers? Or how they fired with this order? > > > > I have read it, but I don't understand it. > > Do you have a good example? create table disable_trigger_test(id int PRIMARY KEY, fld_1 text); insert into disable_trigger_test values (1, 'dog'), (2, 'cat'); test=> select * from disable_trigger_test ; id | fld_1 ----+------- 1 | dog 2 | cat pg_dump --disable-triggers -d test -U aklaver -t disable_trigger_test -a -f disable_trigger_test_data.sql CREATE OR REPLACE FUNCTION public.trigger_test() RETURNS trigger LANGUAGE plpgsql AS $function$ begin new.fld_1 := new.fld_1 || 'test'; RETURN NEW; end; $function$; CREATE TRIGGER tr_test BEFORE INSERT ON disable_trigger_test FOR EACH ROW EXECUTE PROCEDURE public.trigger_test(); truncate disable_trigger_test ; #Note I do this as a superuser. psql -d test -U postgres -f disable_trigger_test_data.sql test=> select * from disable_trigger_test ; id | fld_1 ----+------- 1 | dog 2 | cat test=> insert into disable_trigger_test values (3, 'fish'); INSERT 0 1 test=> select * from disable_trigger_test ; id | fld_1 ----+---------- 1 | dog 2 | cat 3 | fishtest (3 rows) > > Thanks! > dd -- Adrian Klaver adrian.klaver@aklaver.com