If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > deadlock between 2 tables during update operation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-26-10, 07:57
infyravi infyravi is offline
Registered User
 
Join Date: Apr 2010
Posts: 19
deadlock between 2 tables during update operation

Hi,

We are using DB2 UDB V8 and are experiencing some strange deadlocks between tables during the update operation.

we are having one "order" table and other "xorder" table and they share foreign key relationship.

we are using entity beans for doing the CRUP operations on these tables
and for quite some time we have noticed that update on these tables is resulting into deadlock.

How can we avoid deadlock scenarios in such cases?

Thanks
Ravi
Reply With Quote
  #2 (permalink)  
Old 05-26-10, 08:09
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
First you need to make sure that it is a deadlock that you are experiencing. The error message you get shares the same message with a lock timeout. Only the return code tells you what occurred, 2 = deadlock and 68 = timeout.

The best way to prevent deadlocks is to always update the table in the same order. Either update the ORDER table first or the XORDER table first, but always do it the same way.

Andy
Reply With Quote
  #3 (permalink)  
Old 05-26-10, 09:35
infyravi infyravi is offline
Registered User
 
Join Date: Apr 2010
Posts: 19
deadlock between 2 tables during update operation

Hi,
Yes they are resulting into deadlocks only we have crossed checked the
errors.
How it will be handled in concurrent user scenario.Will it not result into
deadlock?

Thanks
Ravi
Reply With Quote
  #4 (permalink)  
Old 05-26-10, 09:52
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
If both applicaitons lock the tables in the same sequence, then there may be a slight lock-wait, but not a deadlock (deadly embrace). A deadlock occurs when 2 applications (or more) already hold some locks, and try to acquire other locks that another application is holding, so it can never be resolved by simply waiting and therefor DB2 will pick a victum and cancel it to allow the other to proceed.

You can set up (or look at existing) deadlock event monitor to determine which SQL statements are deadlocking (if you have a detailed deadlock monitor set up). I don't recall if V8 has detailed deadlock event monitors, but I think so. You will need to run a program to format the deadlock event files into a report (see the Command Reference manual for details).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 07-13-10, 10:41
infyravi infyravi is offline
Registered User
 
Join Date: Apr 2010
Posts: 19
deadlock between 2 tables during update operation

what is the solution to fix this issue.
Deadlock happening on 2 update statements.
Is it that orders and xorders table should be updated in the same order in the entire application.
From the deadlock monitor we found that deadlock is happening on update of these 2 tables only and when I am checking the application ids they are different for both the tables

Application ID : GA141A3D.FDDE.1A3D53132446
Application ID : GA141A3D.F372.19AA63130725
Table space is also same for the tables.

Thanks
Ravi
Reply With Quote
  #6 (permalink)  
Old 07-13-10, 10:44
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Yes, you should always update the tables in the same order. This should fix the deadlocks.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On