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 > Deadlocks and view

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-22-05, 14:22
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Deadlocks and view

I have two tables, let's call them A and B.

I have a view, call it V, which is defined as:
SELECT * FROM A, B WHERE A.ID = B.ID

Now I have an application #1 that has to update A and B. So I did an update to A, then I updated B.

It's a live system, though, so in middle, applicatoin #2 asked for "select * from V".

SQL0911 rc=2. From the event monitor, I can see that #1 has a lock on A, #2 has a lock on B.

I have re-written #1 so it updates B then A, but it occurs to me that I have no guarantee from DB2 that "select * from V" will always get lock B before A. In fact the way the view is defined suggests the opposite.

Help.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #2 (permalink)  
Old 11-23-05, 11:10
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Bumping, hopefully someone has an idea.

I expect the only solution is just to keep the time between the update on A and the update on B as short as possible to reduce the possibility of someone grabbing the B lock before we get a chance.

jono
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 11-23-05, 12:01
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
What isolation level the SELECT uses? Can you change it to a lower level?

You may want to do "select ... for update" on both A and B _before_ actually updating it - at least you'll get a lock timeout instead of a deadlock, which you can catch and re-try...
Reply With Quote
  #4 (permalink)  
Old 11-23-05, 12:25
juliane26 juliane26 is offline
Registered User
 
Join Date: Oct 2005
Posts: 109
How about the DB2 registry variables DB2_SKIPINSERTED or DB2_SKIPDELETED and DB2_EVALUNCOMMITTED ??

ok, the last would not help since no where-condition is specified.
But DB2_SKIPINSERTED sounds good ...
__________________
Juliane
Reply With Quote
  #5 (permalink)  
Old 11-23-05, 13:02
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by n_i
What isolation level the SELECT uses? Can you change it to a lower level?

You may want to do "select ... for update" on both A and B _before_ actually updating it - at least you'll get a lock timeout instead of a deadlock, which you can catch and re-try...
Both run as CS, so there isn't a practical lower level.

I'll try the SELECT ... FOR UPDATE, that might work.

I've set DB2_SKIPINSERTED, DB2_SKIPDELETED, DB2_EVALUNCOMMITTED, to no effect. Since it's an UPDATE, only EVALUNCOMMITTED really applies, and because the row is a matching row it still needs to lock.
__________________
--
Jonathan Petruk
DB2 Database Consultant
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