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;

可以通过在命令行界面执行commit命令或者kill掉阻塞session 314的会话,如果kill掉阻塞314的会话会造成语句的回滚。
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;

可以通过在命令行界面执行commit命令或者kill掉阻塞session 314的会话,如果kill掉阻塞314的会话会造成语句的回滚。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21374452/viewspace-2131462/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21374452/viewspace-2131462/