Re: Adding foreign key constraints without integrity check?

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Wes <wespvp(at)syntegra(dot)com>
Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding foreign key constraints without integrity check?
Date: 2006-06-19 10:34:39
Message-ID: 44967DBF.9050308@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gurjeet Singh 2006-06-19 12:00:00 Re: A slow query - Help please?
Previous Message Alban Hertroys 2006-06-19 10:25:58 Re: A slow query - Help please?