Re: Foreign key slows down copy/insert - Mailing list pgsql-performance

From Christopher Kings-Lynne
Subject Re: Foreign key slows down copy/insert
Date
Msg-id 425E88B7.6000203@familyhealth.com.au
Whole thread Raw
In response to Re: Foreign key slows down copy/insert  (Richard van den Berg <richard.vandenberg@trust-factory.com>)
Responses Re: Foreign key slows down copy/insert
Re: Foreign key slows down copy/insert
List pgsql-performance
> Thanks for the pointer. I got this from the archives:
>
> ------------------------
> update pg_class set reltriggers=0 where relname = 'YOUR_TABLE_NAME';
>
> to enable them after you are done, do
>
> update pg_class set reltriggers = count(*) from pg_trigger where
> pg_class.oid=tgrelid and relname='YOUR_TABLE_NAME';
> ------------------------
>
> I assume the re-enabling will cause an error when the copy/insert added
> data that does not satisfy the FK. In that case I'll indeed end up with
> invalid data, but at least I will know about it.

No it certainly won't warn you.  You have _avoided_ the check entirely.
  That's why I was warning you...

If you wanted to be really careful, you could:

being;
lock tables for writes...
turn off triggers
insert
delete where rows don't match fk constraint
turn on triggers
commit;

Chris

pgsql-performance by date:

Previous
From: "Mohan, Ross"
Date:
Subject: Re: Intel SRCS16 SATA raid?
Next
From: Richard van den Berg
Date:
Subject: Re: Foreign key slows down copy/insert