Professional Documents
Culture Documents
Deadlocks Why Ithappens
Deadlocks Why Ithappens
Deadlocks Why Ithappens
2012
Deadlocks
Deadlocks
What are deadlocks? The "classic" deadlock What happens to both sessions? So, what's the fix? Deadlocks with Autonomous Transactions Deadlocks with Bitmap Indexes Deadlocks with unindexed foreign keys Detecting and identifying deadlocks Further information
30.8.2012
Deadlocks
Okay, now session 2 attempts to delete row 'y', again, not committing :
SS2 dlt fo tweea='' ES> eee rm hr y; 1rwdltd o eee.
Now, since session 2 has not committed the delete against row 'y', session 1 can still "see" it (and attempt to delete it) :
SS1 dlt fo tweea='' ES> eee rm hr y;
However, this will be blocked by session 2 (and hence wait), since row 'y' is locked, so session 1 is holding the lock on row 'x' but is waiting for row 'y'. Now, session 2 attempts to do it the "other way around", i.e. attempting to delete row 'x', while it retains the lock on row 'y' :
SS2 dlt fo tweea='' ES> eee rm hr x;
this will be blocked by session 1 (and hence wait). So, the situation is tied, session 2 is waiting for session 1 and session 1 is waiting for session 2. So, in reality, what happens in this situation? Well, obviously deadlocks just simply can't be allowed to occur, it's basically an infinite loop, the situation can't be resolved. So, Oracle steps in, automatically detecting the deadlock and resolving it by causing one of the sessions (can't actually guarantee which one) to receive an ORA-00060 error, i.e.
OA000 dalc dtce wiewiigfrrsuc R-06: edok eetd hl atn o eore
What happens to both sessions? So, we've seen what happens in terms of the deadlock, one of the sessions will error with the ORA-00060 error, but what about the other one? Well, this may be surprising to some people, but it carries on waiting, because the ORA-00060 error in the other session does not commit or rollback, and hence it retains it's previous lock(s), including those involved in the deadlock scenario. It is the responsibility of the client to commit or rollback if an ORA-00060 error is encountered. So, what's the fix? As with all deadlock scenarios, it's about avoidance rather than remedy. For the classic deadlock situation, you have to ensure that sessions do their operations in the same "order", i.e. if a process updates table t1 then t2, that any other process does so in the same order.
30.8.2012
Deadlocks
Now, since the "parent" session is locking the row in "t", any attempt to delete it via an AT from within the "parent" session, will result in ORA-00060, i.e.
SL ee pa; Q> xc _t BGNpa;ED EI _t N; * ERRa ln 1 RO t ie : OA000 dalc dtce wiewiigfrrsuc R-06: edok eetd hl atn o eore OA052 a "ATNPA" ln 5 R-61: t MRI._T, ie OA052 a ln 1 R-61: t ie
So, why does the AT simply not block on the 'x' row? Well, if it did, imagine the situation, "parent" session is waiting for the AT to "finish" (like any other PL/SQL call), but it never will since it's blocked waiting for it's parent session to commit or rollback.
30.8.2012
Deadlocks
the bitmap index is maintaining other rows as a result of the DML. Fortunately, it's easy to detect these kind of deadlocks, because the trace file has a very particular format :
Dalc gah edok rp: -----lce()---- -----atrs--------Bokrs-------Wie()---Rsuc Nm eore ae poesssinhlswis poesssinhlswis rcs eso od at rcs eso od at T-080700da X0002-0021 1 2 3 7 X 1 5 3 5 S T-0a0600dd X0001-0062 1 5 3 5 X 1 2 3 7 S ssin3:DD00-0C0000 ssin3:DD00-0F0000 eso 7 I 0100-0002 eso 5 I 0100-0002 ssin3:DD00-0F0000 ssin3:DD00-0C0000 eso 5 I 0100-0002 eso 7 I 0100-0002 Rw wie o: os atd n Ssin3:n rw eso 5 o o Ssin3:n rw eso 7 o o
Note, the "no row" entries. This is the prime indicator that this is a bitmap index deadlock. There's very little you can do about this, apart from not use bitmap indexes in a DML environment.
www.oratechinfo.co.uk/deadlocks.html
4/6
30.8.2012
Deadlocks
Note, the fragment (dictionary objn - 13646, file - 4, block - 15, slot - 1), the objn - 13646 relates to the object_id, which can be queried via dba_objects or similar. Trace file extract for same session with Autonomous Transaction
**20-10 1:42.2 * 061-5 40:038 **ATO NM:)20-10 1:42.2 * CIN AE( 061-5 40:038 **MDL NM:SLPu)20-10 1:42.2 * OUE AE(Q*ls 061-5 40:038 **SRIENM:SSUES 20-10 1:42.2 * EVC AE(Y$SR) 061-5 40:038 **SSINI:2.6 20-10 1:42.2 * ESO D(72) 061-5 40:038 DALC DTCE EDOK EETD [rnato Dalc] Tascin edok CretSLsaeetfrti ssin urn Q ttmn o hs eso: DLT FO T EEE RM ---P/Q Cl Sak---- LSL al tc -ojc bet ln ojc ie bet hnl ade nme nm ubr ae 29D3 0D68 5 poeueMRI._T rcdr ATNPA 1156 DC6C 1 aoyosbok nnmu lc Tefloigdalc i nta OAL err I i a h olwn edok s o n RCE ro. t s dalc det ue erri tedsg o a apiain edok u o sr ro n h ein f n plcto o fo isigicreta-o SL Tefloig r rm sun norc dhc Q. h olwn ifrainmyadi dtriigtedalc: nomto a i n eemnn h edok Dalc gah edok rp: -----lce()---- -----atrs--------Bokrs-------Wie()---Rsuc Nm eore ae poesssinhlswis poesssinhlswis rcs eso od at rcs eso od at T-08030009 X0000-0001 1 8 2 7 X 1 8 2 7 X ssin2:DD00-020001 ssin2:DD00-020001 eso 7 I 0101-000E eso 7 I 0101-000E Rw wie o: os atd n Ssin2:oj-rwd=0034 -AAVAEAAPA eso 7 b oi 005E ADOAAAAAA (itoayoj -166 fl -4 bok-1,so -0 dcinr bn 34, ie , lc 5 lt )
www.oratechinfo.co.uk/deadlocks.html 5/6
30.8.2012
Deadlocks
As you can see, Oracle does a good job of giving as much information about the involved sessions (including "current" SQL statement, etc.).
Further Information
The issue of deadlocks (and how to deal with them) is quite an extensive subject, and there are plenty of web resources for understanding them. Note, the Oracle Metalink links require a metalink account to access.
Ask Tom : Determining which query caused deadlock. Metalink 164661.1 : ORA-60 / Deadlocks Most Common Causes Metalink 171795.1 : Bitmap Indexes and Deadlocks: Deadlocks on Insert Statements Metalink 62365.1 : What to do with "ORA-60 Deadlock Detected" Errors
www.oratechinfo.co.uk/deadlocks.html
6/6