Re: Strange deadlock in foreign key check

From: Sophia Wright <sjw9010(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Strange deadlock in foreign key check
Date: 2015-08-06 23:24:24
Message-ID: CAJTwwh08=5tdg6sUreXJ1RM+j+FFONSSUzZXDrwvmXe1dkx7Tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 7, 2015 at 2:46 AM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> I would also take a look at Alvaro's explanation. My understanding is that
> for locking purposes the UNIQUE index is considered sort of like a FK, as
> it could be used as a FK. This then leads to the FOR UPDATE lock, which
> from Table 13.3 at the link I sent, conflicts with all the other row locks.
>

Like I said, I think it would make sense for a UNIQUE index in pk_rel, i.e.
the fk_rel insert would try to lock pk_rel.id with KEY SHARE, and would end
up locking any other UNIQUE fields as a result.

But I can't see why the pk_rel deletion would want a KEY SHARE lock on
fk_rel. It must be using FOR KEY SHARE rather than FOR UPDATE, since it
does not conflict with the update of fk_rel.pk_id in the first example. So
why lock fk_rel at all, if the lock doesn't include fk_rel.pk_id? Isn't
that the only bit that matters to a pk_rel deletion?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Berend Tober 2015-08-06 23:41:40 Re: How to intelligently work with views that depend on other views
Previous Message Melvin Davidson 2015-08-06 22:50:41 Re: How to intelligently work with views that depend on other views