Re: using deferred initially deferred to solve foreign key checking issues

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Philip de Nier <philip(dot)denier(at)rd(dot)bbc(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: using deferred initially deferred to solve foreign key checking issues
Date: 2006-08-22 21:21:12
Message-ID: 11844.1156281672@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Philip de Nier <philip(dot)denier(at)rd(dot)bbc(dot)co(dot)uk> writes:
> The solutions I could find in the mailing lists were either to upgrade to
> version 8.1 which uses "SELECT ... FOR SHARE" (I'm currently using 8.0),
> stop using foreign keys or add "DEFERRABLE INITIALLY DEFERRED" to the
> constraints. For now I'd prefer to use the last option.

> Does using "DEFERRABLE INITIALLY DEFERRED" completely solve the problem of
> transactions waiting for each other to release locks resulting from "SELECT
> ... FOR UPDATE"?

It doesn't eliminate the problem, but it does narrow the window in which
the lock is held by quite a bit, by postponing the FK checks until just
before transaction commit.

> How are the deferred foreign key constraints checked - are they checked one
> at a time?

Yeah.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-08-22 21:24:10 Re: error msg when pg_restore
Previous Message Tom Lane 2006-08-22 21:09:51 Re: share library version problems