【等待事件】-enq: TX - row lock contention

kakaxi9521發表於2016-12-27
enq: TX - row lock contention 通常是application級別的問題。
enq是一種保護共享資源的鎖定機制,一個排隊機制,先進先出(FIFO)。
enq: TX - row lock contention 的產生有幾種情況。

<1>Waits for TX in mode 6 :A 會話持有row level lock,B會話等待這個lock釋放。
不同的session更新或刪除同一個記錄。(This occurs when one application is updating or deleting a row that another session is also trying to update or delete. )
解決辦法:持有鎖的會話commit或者rollback。

<2>In mode 4,唯一索引
表上存在唯一索引,A會話插入一個值(未提交),B會話隨後也插入同樣的值;A會話提交後,enq: TX - row lock contention消失。
解決辦法:持有鎖的會話commit或者rollback。

<3>in mode 4 :bitmap
源於bitmap的特性:點陣圖索引的一個鍵值,會指向多行記錄,所以更新一行就會把該鍵值指向的所有行鎖定。
解決辦法:commit或者rollback。

<4>其他原因
It could be a primary key problem;  a trigger firing attempting to insert, delete, or update a row; a problem with initrans; waiting for an index split to complete; problems with bitmap indexes;updating a row already updated by another session; or something else. 


實驗:
<1>Waits for TX in mode 6 :A 會話持有row level lock,B會話等待這個lock釋放。

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 Connected as yebiao 
SQL> create table t1(id number,name varchar2(10)); Table created 
SQL> insert into t1 values(1,'tom');
1 row inserted
SQL> select * from t1;
        ID NAME
---------- ----------
         1 tom
SQL> commit;
Commit complete
在一個會話裡執行update
SQL> update t1 set name='john' where id=1;
1 row updated
SQL>
在另一個會話裡也執行updateSQL> update t1 set name='jack' where id=1;  此會話無法執行
通過以下語句檢視存在tx鎖的會話:
select g.Inst_id,g.sid,g.serial#,g.event,g.username, g.sql_hash_value,s.SQL_FULLTEXT
from gv$session g,v$sql s
where g.Wait_class <> 'Idle' and g.sql_hash_value=s.HASH_VALUE;
【等待事件】-enq: TX - row lock contention

可以通過在命令列介面執行commit命令或者kill掉阻塞session 314的會話,如果kill掉阻塞314的會話會造成語句的回滾。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21374452/viewspace-2131462/,如需轉載,請註明出處,否則將追究法律責任。

相關文章