Re: Adding foreign key constraints without integrity

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Wes <wespvp(at)syntegra(dot)com>
Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding foreign key constraints without integrity
Date: 2006-06-19 20:24:57
Message-ID: 1150748696.26538.113.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 2006-06-18 at 22:41, 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.
>
> My database reload is currently taking about 6 hours to load the data, 42
> hours to reindex, and about another 40 hours or so to check the foreign key
> constraints (about 1.2 billion rows). That's a very long time to be out of
> commission. I'd really like to eliminate that second 40 hours so I can get
> it down to a normal weekend.

Are you sure that's really the problem? Do you have indexes on the
referring tables (i.e. the foreign key that points to the other table's
primary key). Not having an index on the subordinate table makes each
and every check on the FK->PK relationship require a seq scan of the
subordinate table.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim Nasby 2006-06-19 20:35:56 Re: MySQL insert() and instr() equiv
Previous Message Bruno Wolff III 2006-06-19 20:20:10 Re: Computing transitive closure of a table