pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Durumdara <durumdara@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Restore - disable triggers - when they fired?
Date: Tue, 20 Mar 2018 08:33:43 -0700
Message-ID: <cdd36500-2d8c-2352-4f1f-b63a024dce15@aklaver.com> (raw)
In-Reply-To: <CAEcMXhnYkiVmcKBVzmrQTe-ukb7cxz=cK2nbnY26A=Ywn2p6ng@mail.gmail.com>
References: <CAEcMXhnt9P=4E7syOurQPgZgnH9XKUU+EoWkx+Vf0W_Q=7-W+g@mail.gmail.com>
	<b98fbad7-2080-603c-5c8b-be95407b5996@aklaver.com>
	<CAEcMXhnYkiVmcKBVzmrQTe-ukb7cxz=cK2nbnY26A=Ywn2p6ng@mail.gmail.com>

On 03/20/2018 07:56 AM, Durumdara wrote:
> Dear Adrian!
> 
> 
> 2018-03-20 15:47 GMT+01:00 Adrian Klaver <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>>:
> 
> 
> 
>         When it would be useful?
> 
> 
>     https://www.postgresql.org/docs/10/static/app-pgrestore.html
>     <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




view thread (6+ messages)  latest in thread

Message-ID: <cdd36500-2d8c-2352-4f1f-b63a024dce15@aklaver.com>
Permalink:  ../cdd36500-2d8c-2352-4f1f-b63a024dce15@aklaver.com/
Also on:    postgresql.org/message-id/cdd36500-2d8c-2352-4f1f-b63a024dce15@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, durumdara@gmail.com
  Subject: Re: Restore - disable triggers - when they fired?
  In-Reply-To: <cdd36500-2d8c-2352-4f1f-b63a024dce15@aklaver.com>
  References: <CAEcMXhnt9P=4E7syOurQPgZgnH9XKUU+EoWkx+Vf0W_Q=7-W+g@mail.gmail.com> <b98fbad7-2080-603c-5c8b-be95407b5996@aklaver.com> <CAEcMXhnYkiVmcKBVzmrQTe-ukb7cxz=cK2nbnY26A=Ywn2p6ng@mail.gmail.com> <cdd36500-2d8c-2352-4f1f-b63a024dce15@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox