Re: Adding foreign key constraints without integrity check? - Mailing list pgsql-general

From Florian G. Pflug
Subject Re: Adding foreign key constraints without integrity check?
Date
Msg-id 44967DBF.9050308@phlo.org
Whole thread Raw
In response to Adding foreign key constraints without integrity check?  (Wes <wespvp@syntegra.com>)
Responses Re: Adding foreign key constraints without integrity
List pgsql-general
Wes wrote:
> Is there a way to add a foreign key constraint without having to wait for it
> to check the consistency of all existing records?  If a database is being
> reloaded (pg_dumpall then load), it really shouldn't be necessary to check
> the referential integrity - or at least I should be able to stipulate that I
> am accepting that risk.
You could create the fk-constraints _first_, then disable them, load
the data, reindex, and reenable them afterwards.

pg_dump/pg_restore can enable and disable fk-constraints before restoring
the data, I believe. It does so by tweaking the system catalogs.

The only problem I can see is that creating the fk-constraints might create
some indices too. But maybe you can manually drop those indices afterwards - I
don't know if the fk really _depends_ on the index, or if it creates it only
for convenience.

greetings, Florian Pflug


pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: A slow query - Help please?
Next
From: "Gurjeet Singh"
Date:
Subject: Re: A slow query - Help please?