Re: Referential Integrity and SHARE locks - Mailing list pgsql-hackers

From Csaba Nagy
Subject Re: Referential Integrity and SHARE locks
Date
Msg-id 1170411255.3101.75.camel@coppola.muc.ecircle.de
Whole thread Raw
In response to Referential Integrity and SHARE locks  ("Simon Riggs" <simon@2ndquadrant.com>)
Responses Re: Referential Integrity and SHARE locks  (Richard Huxton <dev@archonet.com>)
List pgsql-hackers
On Fri, 2007-02-02 at 10:51, Simon Riggs wrote:
[snip]
> Why do we need a SHARE lock at all, on the **referenc(ed)** table?
> 
> It sounds like if we don't put a SHARE lock on the referenced table then
> we can end the transaction in an inconsistent state if the referenced
> table has concurrent UPDATEs or DELETEs. BUT those operations do impose
> locking rules back onto the referencing tables that would not be granted
> until after any changes to the referencing table complete, whereupon
> they would restrict or cascade. So an inconsistent state doesn't seem
> possible to me.
> 
> What am I missing?

Well, here we do have a patch (deployed on production servers) which
does not put the shared lock on the referenced table, and it lets in
occasionally rows in the referencing tables which do not have parent
rows in the referenced table. I'm not sure what is the mechanism, but it
does happen, I can assure you. It happens rare enough that is not
disturbing for us, compared to the deadlocks which happen without the
patch - that's another matter...

In our application we never update any key ids, so only deletes/inserts
come in play, and I guess it happens when a referenced row is deleted
just between a newly inserted child row checks that the parent row
exists and the row is really inserted. Or something like that...

Cheers,
Csaba.




pgsql-hackers by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Function proposal to find the type of a datum
Next
From: Richard Huxton
Date:
Subject: Re: Referential Integrity and SHARE locks