Re: BUG #4648: needless deadlock on tables having foreign-key - Mailing list pgsql-bugs

From Konstantin
Subject Re: BUG #4648: needless deadlock on tables having foreign-key
Date
Msg-id 172745599.1234513839.206304664.53080@mcgi16.rambler.ru
Whole thread Raw
In response to Re: BUG #4648: needless deadlock on tables having foreign-key  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
* Tom Lane <tgl@sss.pgh.pa.us> [Thu, 12 Feb 2009 19:10:34 -0500]:
> [ shrug... ] The "implementation artifact" is that you didn't get a
> deadlock *earlier*.

I agree that such behavior is more plain rather than current.

> You can't expect to update referenced rows and
> referencing rows in the same transaction and not risk deadlock against
> other transactions doing the same thing.

No. One transaction works with referenced rows only. Another with
referencing rows only.

I expect predictability, then flexibility (locks optimization).
So what is your recommendation?
To avoid deadlock do I need lock all referencing rows if I need to
update referenced row(s)?

Something like ` select * from bill1 where pid = 1 or aid = 1 for
update; ` in the first session of example?

pgsql-bugs by date:

Previous
From: Scott Carey
Date:
Subject: 8.3.5: Query Planner takes 15+ seconds to plan Update or Delete queries on partitioned tables.
Next
From: "Nitin"
Date:
Subject: BUG #4651: Postgresql connection error with PHP 5.