This is very simple deadlock case.Instad of event 10046 ( that I have used in previous blog ) to identify initial TX locks this time
I have used flashback version query and flashback transaction query .
So here is demo:
First craete table and populate some rows:
create table t(a int primary key);
insert into t select rownum from dba_tables where rownum <5;
commit;
SQL> @ct
Table created.
4 rows created.
Commit complete.
SQL> select * from t;
A
———-
1
2
3
4
Now cause deadlock by running these updates in 2 different session is following order:
Session 1:
update t set a=5 where a=1;
update t set a=6 where a=2;
Session 2:
update t set a=7 where a=3;
update t set a=8 where a=4;
Session 1:
update t set a=9 where a=3;
Session 2:
update t set a=10 where a=1;
Last update will cause deadlock and my session 1 will die:
update t set a=9 where a=3
*
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
Now when I select from t and see what it looks like:
SQL> select * from t;
A
———-
5
6
7
8
Diagnostic part:
I will first run flashback version query to get transaction ID ( XID ) for my transactions:
SQL> ALTER SESSION SET nls_timestamp_format = ‘DD-MON-YYYY HH24:MI:SS.FF3′;
SQL> l
1 SELECT VERSIONS_XID
2 , VERSIONS_STARTTIME
3 , VERSIONS_ENDTIME
4 , VERSIONS_STARTSCN
5 , VERSIONS_ENDSCN
6 , VERSIONS_OPERATION
7 , a
8 FROM miladin.t VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE
9 ORDER BY
10* VERSIONS_STARTTIME
SQL> /
VERSIONS_XID VERSIONS_STARTTIME VERSIONS_ENDTIME VERSIONS_STARTSCN VERSIONS_ENDSCN V A
—————- —————————— —————————— —————– ————— – ———-
0A0015008B3D0000 23-APR-2009 14:08:54.000 30260800 U 5
0A0015008B3D0000 23-APR-2009 14:08:54.000 30260800 U 6
05000A00162C0000 23-APR-2009 14:09:00.000 30260807 U 7
05000A00162C0000 23-APR-2009 14:09:00.000 30260807 U 8
23-APR-2009 14:09:00.000 30260807 3
23-APR-2009 14:09:00.000 30260807 4
23-APR-2009 14:08:54.000 30260800 1
23-APR-2009 14:08:54.000 30260800 2
8 rows selected. (more…)