Why do we need an AccessExclusiveLock to validate a FK constraint marked as NOT VALID?

From: Torsten Förtsch <torsten(dot)foertsch(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Why do we need an AccessExclusiveLock to validate a FK constraint marked as NOT VALID?
Date: 2014-04-13 10:58:31
Message-ID: 534A6DD7.5060007@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

currently, ALTER TABLE VALIDATE CONSTRAINT for foreign key constraints
acquires an AccessExclusiveLock on the referencing table.

Why?

If the constraint is in place but not validated (ADD CONSTRAINT ... NOT
VALID) it already prevents new modifications from violating the constraint.

The code that is called to validate the constraint, RI_Initial_Check,
contains this comment:

* We expect that the caller has made provision to prevent any problems
* caused by concurrent actions. This could be either by locking rel and
* pkrel at ShareRowExclusiveLock or higher, or by otherwise ensuring
* that triggers implementing the checks are already active.
* Hence, we do not need to lock individual rows for the check.

Doesn't the presence of the NOT VALID constraint qualify as "otherwise
ensuring that triggers implementing the checks are already active"?

Is there any deeper reason? Or is it simply not implemented yet?

Thanks,
Torsten

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vik Fearing 2014-04-13 11:34:20 Re: Why do we need an AccessExclusiveLock to validate a FK constraint marked as NOT VALID?
Previous Message Jan Wieck 2014-04-12 19:36:15 Re: WAL Replication Server + repmgr + Slony