和Oracle性能优化密切相关的一些知识参考如下Blog:
Oracle 常见的33个等待事件
http://blog.csdn.net/tianlesoftware/archive/2010/08/12/5807800.aspx
锁 死锁 阻塞 Latch 等待 详解
http://blog.csdn.net/tianlesoftware/archive/2010/08/20/5822674.aspx
Oracle Latch 说明
http://blog.csdn.net/tianlesoftware/archive/2010/01/27/5263238.aspx
在网上搜到一篇介绍enq: TX 和 enq:TM的文章。原文地址如下:
http://aprakash.wordpress.com/2011/01/17/enq-tx-row-lock-contention-and-enqtm-contention/
Enqueue 这个词其实是lock 的另一种描述语。当我们在AWR 报告中发现长时间的enqueue 等待事件时,说明数据库中出现了阻塞和等待,可以关联AWR报告中的enqueue activity部分来确定是哪一种锁定出现了长时间等待。
关于Enqueue的所有类型参考《Oracle 常见的33个等待事件》中的Equeue说明。 在这里,我们看一下enq:TX 和 enq:TM
一. enq: TX row lock contention
enq:Tx 会在模式6和4 下出现。
Oracle 的enqueue 包含以下模式:
模式代码
|
类型
|
解释
|
1
|
Null
|
Null mode
|
2
|
SS
|
Sub-Share
|
3
|
SX
|
Sub-Exclusive
|
4
|
S
|
Share
|
5
|
SSX
|
Share/Sub-Exclusive
|
6
|
X
|
Exclusive
|
1.1 enq” TX row lock contention - Mode 6 (Exclusive)
Session 1
==========
ANAND@MATRIX> select * from sa;
A B
---------- ----------
1 1
2 2
3 3
4 4
5 5
Elapsed: 00:00:00.03
ANAND@MATRIX> delete from sa where A=5;
1 row deleted.
Elapsed: 00:00:00.00
From session 2
=====================
ANAND@MATRIX> delete from sa where a=5;
Checking from sys session (session # 3)
Session 3
============
SYS@MATRIX> select addr,xidusn,xidslot,xidsqn,ubafil,ubablk,ubasqn,ses_addr,xid from v$transaction;
addr xidusn xidslot xidsqn ubafil ubablk ubasqn ses_addr xid
-------- ---------- ---------- ---------- ---------- ---------- ---------- -------- ----------------
218B6D98 10 29 848 3 2661 339 232C8B5C 0A001D0050030000
Elapsed: 00:00:00.01
SYS@MATRIX> @lock_sid
Enter value for sid: 135
old 82: where sid = &sid
new 82: where sid = 135
sid lock type id1 id2 lock held lock request time held status
----- ---------------------------------------- --------- --------- -------------- ----------------
135 ???? 65921 1 Row Exclu(3) None(0) 5079.000 Not Blocking
135 DML enqueue 75404 0 Row Exclu(3) None(0) 49.000 Not Blocking
135 ???? 100 0 Share(4) None(0) 5224.000 Not Blocking
135 Transaction 655389 848 Exclusive(6) None(0) 49.000 Blocking
SYS@MATRIX> @sw 135
old 38: sid IN (&1)
new 38: sid IN (135)
sid state event seq# sec_in_wait p1 p2 p3 p1transl
------- ------- ---------------------------------------- ---------- ----------- ------------------ ------------------ ------------------ ------------------------------------------
135 WAITING SQL*Net message from client 193 131 driver id= #bytes= 1 0
0x0000000042455100
SYS@MATRIX> @sw 10
old 38: sid IN (&1)
new 38: sid IN (10)
sid state event seq# sec_in_wait p1 p2 p3 p1transl
------- ------- ---------------------------------------- ---------- ----------- ------------------
10 WAITING enq: TX - row lock contention 35 146 name|mode= usn<
SYS@MATRIX>@enqueue
INST_ID SESS ID1 ID2 Lock Held Lock Requested Lock Type
---------- ------------------------------------------------ -------- -------- --------- --------------
1 Holder: 135 655389 848 6 0 TX
1 Waiter: 10 655389 848 0 6 TX
Back to session 1
==================
ANAND@MATRIX> commit;
Commit complete.
Elapsed: 00:00:00.01
Session 2
===============
22:22:52 ANAND@MATRIX> delete from sa where a=5;
0 rows deleted.
Elapsed: 00:05:07.70
1.2. enq: TX row lock contention – Mode 4
The common cause for mode 4, enq: TX row lock contention are
(1)Unique Index
(2)Foreign key
(3)Bitmap indexes
1.2.1 Unique Index
Session 1
============
ANAND@MATRIX> alter table sa add constraint pk_sa primary key (B);
Table altered.
Elapsed: 00:00:00.29
ANAND@MATRIX> desc sa
Name Null? Type
----------------------------------------------------------------------------------------------
A NUMBER
B NOT NULL NUMBER
ANAND@MATRIX> select * from sa;
A B
---------- ----------
1 1
2 2
3 3
4 4
Elapsed: 00:00:00.04
ANAND@MATRIX> insert into sa values (5,5);
1 row created.
Elapsed: 00:00:00.01
Didn’t commit. Check session 2
Session 2
===============
ANAND@MATRIX> insert into sa values (5,5);
The session hangs.Check the session waits and enqueues.
Session 3
==============
SYS@MATRIX> @lock_sid
Enter value for sid: 135
old 82: where sid = &sid
new 82: where sid = 135
SID Lock Type ID1 ID2 Lock Held Lock Request Time Held STATUS
----- ---------------------------------------- --------- --------- -------------- ----------------
135 ???? 65921 1 Row Exclu(3) None(0) 5779.000 Not Blocking
DML enqueue 75404 0 Row Exclu(3) None(0) 134.000 Not Blocking
???? 100 0 Share(4) None(0) 5924.000 Not Blocking
Transaction 393229 1069 Exclusive(6) None(0) 134.000 Blocking
Elapsed: 00:00:00.03
SYS@MATRIX> @enqueue
INST_ID SESS ID1 ID2 Lock Held Lock Requested Lock Type
---------- ------------------------------------------------ -------- -------- --------- --------------
1 Holder: 135 393229 1069 6 0 TX
1 Waiter: 10 393229 1069 0 4 TX
Elapsed: 00:00:00.04
SYS@MATRIX> @sw 135
old 38: sid IN (&1)
new 38: sid IN (135)
sid state event seq# sec_in_wait p1 p2 p3 p1transl
------- ------- ---------------------------------------- ---------- ----------- ------------------
135 WAITING SQL*Net message from client 229 45 driver id= #bytes= 1 0
0x0000000042455100
Elapsed: 00:00:00.01
SYS@MATRIX> @sw 10
old 38: sid IN (&1)
new 38: sid IN (10)
sid state event seq# sec_in_wait p1 p2 p3 p1transl
------- ------- ---------------------------------------- ---------- ----------- ------------------
10 WAITING enq: TX - row lock contention 44 26 name|mode= usn<<16 | slot= sequence= 1069 0x54580004: TX mode 4 0x0000000054580004 393229
After commit on session1 , the session 2 throws Unique constraint violated error
Session 2
============
ANAND@MATRIX> insert into sa values (5,5);
insert into sa values (5,5)
*
ERROR at line 1:
ORA-00001: unique constraint (ANAND.PK_SA) violated
Elapsed: 00:02:18.10
1.2.2 Foreign key
Session 1
===========
ANAND@MATRIX> create table sa_child (id number references sa(B) ,name varchar2(10));
Table created.
Elapsed: 00:00:00.25
ANAND@MATRIX> select constraint_name,constraint_type,table_name,r_constraint_name,status from user_constraints where table_name in ('sa','sa_child');
CONSTRAINT_NAME C TABLE_NAME R_CONSTRAINT_NAME STATUS
------------------------------ - ------------------------------ ------------------------------ --------
PK_SA P SA ENABLED
SYS_C0011533 R SA_CHILD PK_SA ENABLED
Elapsed: 00:00:00.18
ANAND@MATRIX> insert into sa values (6,6);
1 row created.
Elapsed: 00:00:00.03
Lets insert the same value 6 in SA_CHILD from Session 2
Session 2
===========
ANAND@MATRIX> insert into sa_child values (6,'DANNY');
Session 2 hangs.
Session 3
===========
SYS@MATRIX> @enqueue
INST_ID SESS ID1 ID2 Lock Held Lock Requested Lock Type
---------- ------------------------------------------------ --------- --------- --------- -------------- -----------
1 Holder: 135 655360 884 6 0 TX
1 Waiter: 10 655360 884 0 4 TX
SYS@MATRIX> @lock_sid
Enter value for sid: 135
old 82: where sid = &sid
new 82: where sid = 135
SID Lock Type ID1 ID2 Lock Held Lock Request Time Held STATUS
----- ---------------------------------------- --------- --------- -------------- ---------------- ----------- --------------------
135 DML enqueue 75594 0 Row Exclu(3) None(0) 64.000 Not Blocking
DML enqueue 75404 0 Row Exclu(3) None(0) 64.000 Not Blocking
???? 100 0 Share(4) None(0) 183421.000 Not Blocking
Transaction 655360 884 Exclusive(6) None(0) 64.000 Blocking
6 rows selected.
Elapsed: 00:00:00.09
SYS@MATRIX> @sw 10
old 38: sid IN (&1)
new 38: sid IN (10)
SID STATE EVENT SEQ# SEC_IN_WAIT P1 P2 P3 P1TRANSL
------- ------- ---------------------------------------- ---------- ----------- ------------------ ------------------ ------------------ -------------------------------
10 WAITING enq: TX - row lock contention 58 27 name|mode= usn<<16 | slot= sequence= 884 0x54580004: TX mode 4 0x0000000054580004 655360
Elapsed: 00:00:00.03
SYS@MATRIX> @sw 135
old 38: sid IN (&1)
new 38: sid IN (135)
SID STATE EVENT SEQ# SEC_IN_WAIT P1 P2 P3 P1TRANSL
------- ------- ---------------------------------------- ---------- ----------- ------------------
135 WAITING SQL*Net message from client 686 59 driver id= #bytes= 1 0 0x0000000042455100
So, the session 2 is waiting for enq: TX row lock contention as before inserting the row it needs check for the value in the parent table.If the row is not there , then it would throw erroe “ORA-02291: integrity constraint (ANAND.SYS_C0011533) violated – parent key not found”.
After commit on session1 ,
Session 2
===========
ANAND@MATRIX> insert into sa_child values (6,'DANNY');
1 row created.
Elapsed: 00:05:02.03
1.2.3 Bitmap Index
Session 1
==========
ANAND@MATRIX> select * from sa;
A B C
---------- ---------- ----------
1 1 99
2 2 99
3 3 99
4 4 99
6 6 99
5 5 99
7 7 99
7 rows selected.
Elapsed: 00:00:00.06
ANAND@MATRIX> create bitmap index sa_c_bit_indx on sa(C);
Index created.
Elapsed: 00:00:00.10
ANAND@MATRIX> insert into sa values (8,8,99);
1 row created.
Elapsed: 00:00:00.03
Lets try deleteing a row from sa table from Session 2
Session 2
=============
ANAND@MATRIX> delete from sa where A=1;
Session 2 hangs.
Session 3
===========
SYS@MATRIX> @lock_sid
Enter value for sid: 135
old 82: where sid = &sid
new 82: where sid = 135
SID Lock Type ID1 ID2 Lock Held Lock Request Time Held STATUS
----- ---------------------------------------- --------- --------- -------------- ---------------- ----------- ----------------------------------------
135 DML enqueue 75404 0 Row Exclu(3) None(0) 87.000 Not Blocking
DML enqueue 75594 0 Row Exclu(3) None(0) 87.000 Not Blocking
???? 100 0 Share(4) None(0) 185049.000 Not Blocking
<span style
分享到:
相关推荐
本文将详细介绍一个具体的案例——enq: IV - contention,这是一种常见的队列等待事件,在Oracle 12c版本中尤为突出。通过分析此案例,读者可以深入理解如何使用AWR来定位和解决问题。 #### 二、案例背景 在本案例...
cause:当插入新的索引条目时,发现索引块中没有足够的空间容纳新的索引条目,索引块就会产生分裂(分为5-5分裂...这时就会表现为enq: TX - index contention。本例中索引块分裂属于5-5 分裂,此分裂可以通过awr报告观察
【故障处理】enq: PS - contention 是一个Oracle数据库中常见的等待事件,通常与并行服务器(Parallel Server)的资源竞争有关。这篇博客主要讲解如何解决这类问题,并提供了详细的故障分析和解决步骤。 1. **等待...
通过分析AWR报告中的等待事件和Top5TimedEvents部分,可以发现性能瓶颈所在。在本案例中,enq:SQ-contention和DFSlockhandle是需要重点关注的等待事件。通过调整序列cache值可以减少序列值获取过程中的竞争和等待...
- **V$LOCK**:显示当前锁定的信息,包括锁定模式和等待状态。 - **V$ENQUEUE**:提供有关Enqueue队列等待的具体信息,包括等待类型和锁定对象ID。 - **DBA_OBJECTS**:查看数据库对象的状态,包括是否被锁定。 ...
本篇博客主要聚焦于四种特定的序列等待事件:enq SQ - contention、row cache lock、DFS lock handle和enq SV - contention。 1. **enq SQ - contention**: 这个等待事件发生在多个会话尝试获取对序列(sequence...
### 故障处理:Oracle_lhr_队列等待之TX - row lock contention #### 一、概述 在Oracle数据库管理中,“enq:TX-rowlockcontention”是一种常见的队列等待事件,通常与行级别的锁定冲突有关。这种冲突可能会导致...
以SID为269的会话为例,如果它正等待enq:TX — row lock contention事件,意味着它在等待另一个会话释放锁。在Oracle 10g之前,找出阻塞会话可能需要编写资源密集型查询,但在10g中,只需简单查询v$session就能找到...
例如,对于"enq:TX - row lock contention"这类等待事件,可能需要考虑事务的并发控制策略或锁的粒度。 总之,Oracle 10g的等待界面改进极大地增强了DBAs在性能监控和问题诊断方面的能力。结合ADDM的自动化分析和...
- 等待资源:比如enq: TM - contention和library cache lock。 - 用户进程等待:比如log file parallel write和log file sync。 ### OWI性能调优方法 针对Oracle等待事件进行调优,通常需要一系列的分析和诊断步骤...
- 使用`v$session_wait`视图查找等待类型的`ENQ: TX - row lock contention`或`ENQ: TX - deadlock`。 - 查询`v$deadlock`和`v$deadlock_monitor`视图获取死锁信息。 - 执行`DBMS_LOCK.MONITOR`过程来监控死锁...
- **enq:TX-rowlock contention**:行级锁争用,表示两个或多个会话尝试在同一行上执行不兼容的操作。 - **latch free**:闩锁等待,表示进程正在等待一个当前被其他进程占用的闩锁。 #### 三、使用与查看数据库...
当系统activity增加或者降低的时候,oracle SMON进程会自动ONLINE或者OFFLINE rollback segments。这样导致某些与undo segments相关的latch或者enqueue被...导致系统很多活跃session都开始等待enq: US - contention。
1. **等待事件类型**:`EVENT`字段列出了具体的等待事件名称,如“db file sequential read”表示顺序读取数据库文件,“enq: TX - row lock contention”表示行级锁竞争。 2. **等待时长**:`TIME_WAITED`字段提供...
- 锁等待情况(如ENQ: TX - ROW LOCK contention) Prometheus会定期抓取oracledb-exporter提供的这些指标,并根据预设的规则进行报警和可视化展示。你可以利用Prometheus的Alertmanager设置告警规则,当特定指标...
我们还发现Log file sync会话 -> Lgwr进程(enq: CF – contention)-> ARC6进程(control file sequential read),导致IO慢。 DTRACE是一个强大的工具,可以帮助我们快速定位系统瓶颈和问题根源。在本案例中,...
数据库性能分析显示,主要的性能瓶颈在于用户I/O,尤其是db file sequential read和db file scattered read事件,以及enq: TX - row lock contention,这些都可能导致新Session无法启动或需要更多内存来处理更多的...
- **行锁争用(enq:TX – row lock contention)**:在并发事务处理中,行锁争用是常见的问题之一。当多个事务尝试同时修改同一数据行时,就可能发生此类等待事件。 - **用户I/O**: - 单块读取(single block read...