Deadlocks
This article shows the steps necessary to identify the offending application code when a deadlock is detected.
oracle miscconfigurationintermediate
by OracleDba
12 views
This article shows the steps necessary to identify the offending application code when a deadlock is detected.
123456789101112131415161718192021
CREATE USER test IDENTIFIED BY test
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON users;
GRANT CONNECT, CREATE TABLE TO test;
GRANT EXECUTE ON DBMS_LOCK TO test;
CONN test/test
CREATE TABLE deadlock_1 (
id NUMBER
);
CREATE TABLE deadlock_2 (
id NUMBER
);
INSERT INTO deadlock_1 (id) VALUES (1);
INSERT INTO deadlock_2 (id) VALUES (1);
COMMIT;1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
-- Run in session 1.
DECLARE
l_deadlock_1_id deadlock_1.id%TYPE;
l_deadlock_2_id deadlock_2.id%TYPE;
BEGIN
-- Lock row in first table.
SELECT id
INTO l_deadlock_1_id
FROM deadlock_1
WHERE id = 1
FOR UPDATE;
-- Pause.
DBMS_LOCK.sleep(30);
-- Lock row in second table.
SELECT id
INTO l_deadlock_2_id
FROM deadlock_2
WHERE id = 1
FOR UPDATE;
-- Release locks.
ROLLBACK;
END;
/
-- Run in session 2.
DECLARE
l_deadlock_1_id deadlock_1.id%TYPE;
l_deadlock_2_id deadlock_2.id%TYPE;
BEGIN
-- Lock row in second table.
SELECT id
INTO l_deadlock_2_id
FROM deadlock_2
WHERE id = 1
FOR UPDATE;
-- Pause.
DBMS_LOCK.sleep(30);
-- Lock row in first table.
SELECT id
INTO l_deadlock_1_id
FROM deadlock_1
WHERE id = 1
FOR UPDATE;
-- Release locks.
ROLLBACK;
END;
/
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
ORA-06512: at line 16
ORA-00060: Deadlock detected. More info in file c:\oracle\product\10.2.0\admin\db10g\udump\db10g_ora_4200.trc.12345678910111213141516171819202122232425262728293031323334353637383940
*** 2006-09-13 09:11:40.646
*** ACTION NAME:() 2006-09-13 09:11:40.615
*** MODULE NAME:(SQL*Plus) 2006-09-13 09:11:40.615
*** SERVICE NAME:(SYS$USERS) 2006-09-13 09:11:40.615
*** SESSION ID:(137.7008) 2006-09-13 09:11:40.615
DEADLOCK DETECTED
[Transaction Deadlock]
Current SQL statement for this session:
SELECT ID FROM DEADLOCK_2 WHERE ID = 1 FOR UPDATE
----- PL/SQL Call Stack -----
object line object
handle number name
1AFBE484 16 anonymous block
The following deadlock is not an ORACLE error. It is a
deadlock due to user error in the design of an application
or from issuing incorrect ad-hoc SQL.
The following
information may aid in determining the deadlock:
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TX-0006001a-0000131b 19 137 X 24 159 X
TX-00030028-00001313 24 159 X 19 137 X
session 137: DID 0001-0013-000067B7 session 159: DID 0001-0018-0000100C
session 159: DID 0001-0018-0000100C session 137: DID 0001-0013-000067B7
Rows waited on:
Session 159: obj - rowid = 0000E6C7 - AAAObHAAEAAAABAAAA
(dictionary objn - 59079, file - 4, block - 64, slot - 0)
Session 137: obj - rowid = 0000E6C8 - AAAObIAAEAAAABIAAA
(dictionary objn - 59080, file - 4, block - 72, slot - 0)
Information on the OTHER waiting sessions:
Session 159:
pid=24 serial=51383 audsid=43465 user: 62/TEST
O/S info: user: tim_hall, term: winxp1, ospid: 5928:3844, machine: winxp1
program: sqlplusw.exe
application name: SQL*Plus, hash value=3669949024
Current SQL Statement:
SELECT ID FROM DEADLOCK_1 WHERE ID = 1 FOR UPDATE
End of information on OTHER waiting sessions.
===================================================Please to add comments
No comments yet. Be the first to comment!