dbTalk Databases Forums  

Deadlock on the same select for update

comp.databases.postgresql comp.databases.postgresql


Discuss Deadlock on the same select for update in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roman
 
Posts: n/a

Default Deadlock on the same select for update - 02-21-2011 , 07:18 AM






Hi,
I have problem with deadlocks and don't know why it happens. Below is
the log (postgres 9.0, debian):

[11882]DETAIL: Process 11882 waits for ShareLock on transaction
44324308; blocked by process 11884.
Process 11884 waits for ShareLock on transaction 44324307;
blocked by process 11882.

Process 11882: SELECT * FROM teddy WHERE id IN
(112747007,112747008,112747011,112747013,112747015 ,112747016,112747020,112747021,112747022,112747024 ,112747025,112747028,112747030,112747032,112747034 ,112747035,112747038,112747043,112747044,112747045 ,112747050,112747052,112747053)
FOR UPDATE

Process 11884: SELECT * FROM teddy WHERE id IN
(112747007,112747008,112747011,112747013,112747015 ,112747016,112747020,112747021,112747022,112747024 ,112747025,112747028,112747030,112747032,112747034 ,112747035,112747038,112747043,112747044,112747045 ,112747050,112747052,112747053)
FOR UPDATE


Regards,
Roman

Reply With Quote
  #2  
Old   
Matthew Woodcraft
 
Posts: n/a

Default Re: Deadlock on the same select for update - 02-21-2011 , 01:02 PM






Roman <roman.janowczyk (AT) gmail (DOT) com> wrote:
Quote:
I have problem with deadlocks and don't know why it happens. Below is
the log (postgres 9.0, debian):

[11882]DETAIL: Process 11882 waits for ShareLock on transaction
44324308; blocked by process 11884.
Process 11884 waits for ShareLock on transaction 44324307;
blocked by process 11882.

Process 11882: SELECT * FROM teddy WHERE id IN
(112747007,112747008,112747011,112747013,112747015 ,112747016,112747020,112747021,112747022,112747024 ,112747025,112747028,112747030,112747032,112747034 ,112747035,112747038,112747043,112747044,112747045 ,112747050,112747052,112747053)
FOR UPDATE

Process 11884: SELECT * FROM teddy WHERE id IN
(112747007,112747008,112747011,112747013,112747015 ,112747016,112747020,112747021,112747022,112747024 ,112747025,112747028,112747030,112747032,112747034 ,112747035,112747038,112747043,112747044,112747045 ,112747050,112747052,112747053)
FOR UPDATE
The deadlock can happen because the two processes can lock the rows in
a different order.

In practice I believe if you add an ORDER BY to the SELECT FOR UPDATE
queries the locks will be taken in a consistent order (though this
doesn't appear to be a documented guarantee).

-M-

Reply With Quote
  #3  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Deadlock on the same select for update - 02-23-2011 , 08:34 AM



On Mon, 21 Feb 2011 19:02:18 +0000, Matthew Woodcraft wrote:

Quote:
In practice I believe if you add an ORDER BY to the SELECT FOR UPDATE
queries the locks will be taken in a consistent order (though this
doesn't appear to be a documented guarantee).
Deadlocks are also known as circular locks. Locking records in the same
order is a guarantee against deadlocks. That's not a software guarantee,
that's mathematics.



--
http://mgogala.byethost5.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.