Re: Foreign key slows down copy/insert

From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Richard van den Berg <richard(dot)vandenberg(at)trust-factory(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Foreign key slows down copy/insert
Date: 2005-04-14 15:13:59
Message-ID: 425E88B7.6000203@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Richard van den Berg 2005-04-14 15:25:36 Re: Foreign key slows down copy/insert
Previous Message Mohan, Ross 2005-04-14 15:08:32 Re: Intel SRCS16 SATA raid?