"Richard Huxton" <dev@archonet.com> writes:
> Well, foreign keys enforce constraints so it's not unreasonable that the
> lock might extend to the referenced tables.
Precisely. The SELECT FOR UPDATE is done to ensure that the referenced
rows don't go away before the update of the referencing table commits.
I'm guessing that Anand's not shown us all the operations involved,
and that when things hang up it's because there are two different
transactions trying to lock overlapping sets of referenced rows.
Hard to tell from the info we have, however.
regards, tom lane