enq:TM-contention事件等待
enq:TM-contention等待的發生,發生TM鎖爭用的情況如下:
1、修改無索引外來鍵(foreign key)的父鍵時
2、DML與DDL之間的TM爭用
3、LOCK TABLE 引起的TM鎖爭用
4、direct load工作引起的TM鎖爭用
模擬該等待事件
1、建立兩張測試表
JZH@jzh>create table jzh1 as select object_id,object_name from user_objects;
Table created.
JZH@jzh>create table jzh2 as select object_id,object_name from user_objects;
Table created.
2、建立主鍵索引
JZH@jzh>alter table jzh1 add constraint pk_jzh1 primary key(object_id);
Table altered.
3、為jzh2新增外來鍵
JZH@jzh>alter table jzh2 add constraint fk_jzh2 foreign key(object_id) references jzh1 (object_id)on delete cascade;
Table altered.
JZH@jzh>select index_name from user_indexes where table_name='JZH2';
no rows selected
---雖然新增了外來鍵,但沒有建立索引
4、多開幾個session刪除資料
session1:
JZH@jzh>select sid from v$mystat where rownum=1;
SID
----------
1
JZH@jzh>delete from jzh1 where object_NAME='T';
1 row deleted.
session2:
JZH@jzh>delete from jzh1 where object_name='TEST';----hang住了
session3;
JZH@jzh>insert into jzh1 values(1,'JZH');---也被hang住了
5、檢視沒鎖的情況
select a.sid,c.blocking_session blocker,c.event,a.type,a.lmode,a.request,b.object_name,b.object_type from v$lock a,dba_objects b,v$session c where c.username='JZH' and a.id1=b.object_id and a.sid=c.sid;
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- -------------------- ---------- ---------- ---------- --------------- --------------------
32 1 enq: TM - contention AE 4 0 ORA$BASE EDITION
37 32 enq: TM - contention AE 4 0 ORA$BASE EDITION
1 SQL*Net message from AE 4 0 ORA$BASE EDITION
client
1 SQL*Net message from TO 3 0 SDO_GEOR_DDL__T TABLE
client ABLE$$
1 SQL*Net message from TM 3 0 JZH2 TABLE
client
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- -------------------- ---------- ---------- ---------- --------------- --------------------
32 1 enq: TM - contention TM 0 5 JZH2 TABLE
37 32 enq: TM - contention TM 0 3 JZH2 TABLE
1 SQL*Net message from TM 3 0 JZH1 TABLE
client
32 1 enq: TM - contention TM 3 0 JZH1 TABLE
37 32 enq: TM - contention TM 3 0 JZH1 TABLE
10 rows selected.
終於看到了enq: TM - contention等待事件,且sid:1阻塞了sid:32,而sid:32阻塞了sid:37。
6、在外來鍵列上建立索引
JZH@jzh>create index object_id_idx on jzh2(object_id);
Index created.
再重複上面session1-session3步驟
再次查詢:
SYS@jzh>select a.sid,c.blocking_session blocker,c.event,a.type,a.lmode,a.request,b.object_name,b.object_type from v$lock a,dba_objects b,v$session c where c.username='JZH' and a.id1=b.object_id and a.sid=c.sid;
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- ---------------------------------------- ---------- ---------- ---------- --------------- --------------------
32 SQL*Net message from client AE 4 0 ORA$BASE EDITION
37 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client TM 3 0 JZH2 TABLE
37 SQL*Net message from client TM 3 0 JZH2 TABLE
32 SQL*Net message from client TM 3 0 JZH2 TABLE
1 SQL*Net message from client TO 3 0 SDO_GEOR_DDL__T TABLE
ABLE$$
1 SQL*Net message from client TM 3 0 JZH1 TABLE
37 SQL*Net message from client TM 3 0 JZH1 TABLE
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- ---------------------------------------- ---------- ---------- ---------- --------------- --------------------
32 SQL*Net message from client TM 3 0 JZH1 TABLE
10 rows selected.
可以看到已經沒有enq: TM - contention TM等待。
7、利用lock table模擬enq: TM - contention TM 等待
session1:
JZH@jzh>update jzh1 set object_id=1 where object_name='TEST';
1 row updated.
session2:
JZH@jzh>lock table jzh1 in exclusive mode;----hang住了
SYS@jzh>select a.sid,c.blocking_session blocker,c.event,a.type,a.lmode,a.request,b.object_name,b.object_type from v$lock a,dba_objects b,v$session c where c.username='JZH' and a.id1=b.object_id and a.sid=c.sid;
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- ---------------------------------------- ---------- ---------- ---------- --------------- --------------------
32 1 enq: TM - contention AE 4 0 ORA$BASE EDITION
37 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client TM 3 0 JZH1 TABLE
32 1 enq: TM - contention TM 0 6 JZH1 TABLE
1 SQL*Net message from client TO 3 0 SDO_GEOR_DDL__T TABLE
ABLE$$
1 SQL*Net message from client TX 6 0 /155fe610_Const SYNONYM
raintOperator
7 rows selected.
可以看到enq: TM - contention出來了。
1、修改無索引外來鍵(foreign key)的父鍵時
2、DML與DDL之間的TM爭用
3、LOCK TABLE 引起的TM鎖爭用
4、direct load工作引起的TM鎖爭用
模擬該等待事件
1、建立兩張測試表
JZH@jzh>create table jzh1 as select object_id,object_name from user_objects;
Table created.
JZH@jzh>create table jzh2 as select object_id,object_name from user_objects;
Table created.
2、建立主鍵索引
JZH@jzh>alter table jzh1 add constraint pk_jzh1 primary key(object_id);
Table altered.
3、為jzh2新增外來鍵
JZH@jzh>alter table jzh2 add constraint fk_jzh2 foreign key(object_id) references jzh1 (object_id)on delete cascade;
Table altered.
JZH@jzh>select index_name from user_indexes where table_name='JZH2';
no rows selected
---雖然新增了外來鍵,但沒有建立索引
4、多開幾個session刪除資料
session1:
JZH@jzh>select sid from v$mystat where rownum=1;
SID
----------
1
JZH@jzh>delete from jzh1 where object_NAME='T';
1 row deleted.
session2:
JZH@jzh>delete from jzh1 where object_name='TEST';----hang住了
session3;
JZH@jzh>insert into jzh1 values(1,'JZH');---也被hang住了
5、檢視沒鎖的情況
select a.sid,c.blocking_session blocker,c.event,a.type,a.lmode,a.request,b.object_name,b.object_type from v$lock a,dba_objects b,v$session c where c.username='JZH' and a.id1=b.object_id and a.sid=c.sid;
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- -------------------- ---------- ---------- ---------- --------------- --------------------
32 1 enq: TM - contention AE 4 0 ORA$BASE EDITION
37 32 enq: TM - contention AE 4 0 ORA$BASE EDITION
1 SQL*Net message from AE 4 0 ORA$BASE EDITION
client
1 SQL*Net message from TO 3 0 SDO_GEOR_DDL__T TABLE
client ABLE$$
1 SQL*Net message from TM 3 0 JZH2 TABLE
client
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- -------------------- ---------- ---------- ---------- --------------- --------------------
32 1 enq: TM - contention TM 0 5 JZH2 TABLE
37 32 enq: TM - contention TM 0 3 JZH2 TABLE
1 SQL*Net message from TM 3 0 JZH1 TABLE
client
32 1 enq: TM - contention TM 3 0 JZH1 TABLE
37 32 enq: TM - contention TM 3 0 JZH1 TABLE
10 rows selected.
終於看到了enq: TM - contention等待事件,且sid:1阻塞了sid:32,而sid:32阻塞了sid:37。
6、在外來鍵列上建立索引
JZH@jzh>create index object_id_idx on jzh2(object_id);
Index created.
再重複上面session1-session3步驟
再次查詢:
SYS@jzh>select a.sid,c.blocking_session blocker,c.event,a.type,a.lmode,a.request,b.object_name,b.object_type from v$lock a,dba_objects b,v$session c where c.username='JZH' and a.id1=b.object_id and a.sid=c.sid;
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- ---------------------------------------- ---------- ---------- ---------- --------------- --------------------
32 SQL*Net message from client AE 4 0 ORA$BASE EDITION
37 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client TM 3 0 JZH2 TABLE
37 SQL*Net message from client TM 3 0 JZH2 TABLE
32 SQL*Net message from client TM 3 0 JZH2 TABLE
1 SQL*Net message from client TO 3 0 SDO_GEOR_DDL__T TABLE
ABLE$$
1 SQL*Net message from client TM 3 0 JZH1 TABLE
37 SQL*Net message from client TM 3 0 JZH1 TABLE
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- ---------------------------------------- ---------- ---------- ---------- --------------- --------------------
32 SQL*Net message from client TM 3 0 JZH1 TABLE
10 rows selected.
可以看到已經沒有enq: TM - contention TM等待。
7、利用lock table模擬enq: TM - contention TM 等待
session1:
JZH@jzh>update jzh1 set object_id=1 where object_name='TEST';
1 row updated.
session2:
JZH@jzh>lock table jzh1 in exclusive mode;----hang住了
SYS@jzh>select a.sid,c.blocking_session blocker,c.event,a.type,a.lmode,a.request,b.object_name,b.object_type from v$lock a,dba_objects b,v$session c where c.username='JZH' and a.id1=b.object_id and a.sid=c.sid;
SID BLOCKER EVENT TYPE LMODE REQUEST OBJECT_NAME OBJECT_TYPE
---------- ---------- ---------------------------------------- ---------- ---------- ---------- --------------- --------------------
32 1 enq: TM - contention AE 4 0 ORA$BASE EDITION
37 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client AE 4 0 ORA$BASE EDITION
1 SQL*Net message from client TM 3 0 JZH1 TABLE
32 1 enq: TM - contention TM 0 6 JZH1 TABLE
1 SQL*Net message from client TO 3 0 SDO_GEOR_DDL__T TABLE
ABLE$$
1 SQL*Net message from client TX 6 0 /155fe610_Const SYNONYM
raintOperator
7 rows selected.
可以看到enq: TM - contention出來了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10271187/viewspace-1683266/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- enq: WF - contention等待事件ENQ事件
- enq: CF - contention 等待事件ENQ事件
- enq: TS - contention 等待事件ENQ事件
- 等待事件之enq: HW - contention事件ENQ
- 消除 enq: DX - contention 等待事件ENQ事件
- Oracle等待事件之enq: TM – contentionOracle事件ENQ
- 等待事件enq: TX - row lock contention事件ENQ
- oracle等待事件之enq: CF – contentionOracle事件ENQ
- 【等待事件】-enq: TX - row lock contention事件ENQ
- enq:Library cache lock/pin等待事件ENQ事件
- 故障排除 | enq:TX - index contention等待事件ENQIndex事件
- enq: TX - allocate ITL entry等待事件分析ENQ事件
- 等待事件enq TX row lock contention分析事件ENQ
- 如何診斷等待事件 enq: HW - contention事件ENQ
- 【效能調整】等待事件 enq: SQ - contention事件ENQ
- zt_Oracle enq: TX contention 和 enq: TM contention 等待事件OracleENQ事件
- 關於enq: TX - allocate ITL entry等待事件ENQ事件
- 事務上的等待事件 —— enq: UL - contention事件ENQ
- enq: SQ - contention 等待事件處理辦法ENQ事件
- enq: TX - row lock contention等待事件處理ENQ事件
- 記一次enq: RO - fast object reuse等待事件ENQASTObject事件
- oracle 11.2.0.4 rac叢集等待事件enq: TM - contentionOracle事件ENQ
- enq: TM - contention TM 等待事件的原因及模擬ENQ事件
- [20161208]等待事件enq: HW - contention事件ENQ
- [20140311]等待事件enq HW - contention事件ENQ
- enq: KO - fast object checkpoint 等待事件與 direct path read - 1ENQASTObject事件
- enq: KO - fast object checkpoint 等待事件與 direct path read - 2ENQASTObject事件
- enq: KO - fast object checkpoint 等待事件與 direct path read - 3ENQASTObject事件
- [20220518]enq FU - contention等待事件.txtENQ事件
- RAC中的enq: TS等待ENQ
- enq: TX - index contention等待ENQIndex
- 【等待事件】ORACLE常見等待事件事件Oracle
- 【等待事件】等待事件系列(5.1)--Enqueue(佇列等待)事件ENQ佇列
- 等待事件事件
- Solidity事件,等待事件Solid事件
- 【TUNE_ORACLE】等待事件之等待事件類別Oracle事件
- 等待事件分析事件
- oracle等待事件Oracle事件