SQL> select a.sample_time,
2 a.session_id,
3 a.session_serial#,
4 a.blocking_session bsession,
5 a.blocking_session_serial# bserial#,
6 a.event,
7 a.machine,
8 a.module,
9 a.sql_opname
10 from dba_hist_active_sess_history a
11 where a.session_id in (241, 4468, 6819, 10817)
12 and a.sample_time > to_date('2018070310', 'yyyymmddhh24')
13 and a.sample_time < to_date('2018070312', 'yyyymmddhh24')
14 and a.event is not null
15 order by a.sample_time
16 ;
SAMPLE_TIME SESSION_ID SESSION_SERIAL# BSESSION BSERIAL# EVENT MACHINE MODULE SQL_OPNAME
------------------------------ ---------- --------------- ---------- ---------- ------------------------------ ------------------------------ ------------------------------ ----------------------------------------------------------------
03-7月 -18 10.00.40.857 上午 241 425 6587 7875 enq: TM - contention WORKGROUP\TL3050-WZ CWV4.2.8.337_20131204.exe LOCK TABLE
03-7月 -18 10.49.45.384 上午 10817 97 12929 7665 read by other session webserver JDBC Thin Client SELECT
03-7月 -18 10.51.16.143 上午 241 425 4468 2029 enq: TX - row lock contention WORKGROUP\TL3050-WZ CWV4.2.8.337_20131204.exe INSERT
03-7月 -18 10.51.16.143 上午 4468 2029 241 425 enq: TM - contention ZDCW\WANGH88208561 XCV5(新5.24).exe INSERT
03-7月 -18 10.52.46.903 上午 10817 121 null event dbserver1 SELECT
03-7月 -18 10.53.57.464 上午 6819 99 10817 133 enq: TX - row lock contention ZDCW\WANGWD88981612 CWV4.exe INSERT
03-7月 -18 10.53.57.464 上午 10817 133 6819 99 enq: TM - contention ZDCW\WANGH88208561 XCV5(新5.24).exe INSERT
03-7月 -18 10.54.07.554 上午 10817 133 db file parallel read ZDCW\WANGH88208561 XCV5(新5.24).exe INSERT
8 rows selected
3、锁等待的模拟,问题复现
---session1
SQL> lock table pz2018 in exclusive mode;
Table(s) Locked.
----session2
SQL> insert into pzd2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZD_Yong');
1 row created.
SQL> insert into pz2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZ_Yong');
----session2执行直接hang住无法完成,在等待TM锁
SQL> select s.SID,s.BLOCKING_SESSION bsid,s.EVENT,s.MACHINE,s.MODULE,s.STATUS,s.STATE from v$session s where s.EVENT is not null and s.STATUS='ACTIVE' and s.WAIT_CLASS<>'Idle';
SID BSID EVENT MACHINE MODULE STATUS STATE
---------- ---------- ------------------------------ ------------------------------ ---------------------------------------- -------- -------------------
17 143 enq: TM - contention 172-16-8-110 SQL*Plus ACTIVE WAITING
----session1执行
SQL> insert into pzd2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZD_Yong');
--session1 直接hang住,session2抛出错误发现死锁
SQL> insert into pz2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZ_Yong');
insert into pz2018(OBJECT_ID,OBJECT_NAME) values(100000000,'PZ_Yong')
*
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
----检查数据库等待
SQL> set linesize 1000 pagesize 5000
SQL> col EVENT for a30
SQL> col MACHINE for a30
SQL> col MODULE for a40
SQL> select s.SID,s.BLOCKING_SESSION bsid,s.EVENT,s.MACHINE,s.MODULE,s.STATUS,s.STATE from v$session s where s.EVENT is not null and s.STATUS='ACTIVE' and s.WAIT_CLASS<>'Idle';
SID BSID EVENT MACHINE MODULE STATUS STATE
---------- ---------- ------------------------------ ------------------------------ ---------------------------------------- -------- -------------------
143 17 enq: TX - row lock contention 172-16-8-110 SQL*Plus
查看数据库alert日志发现
Thu Jul 05 11:40:40 2018
ORA-00060: Deadlock detected. More info in file /u01/app/oracle/diag/rdbms/dtstack1/dtstack1/trace/dtstack1_ora_29840.trc.
查看死锁trace