公司的一台数据库服务器,Enqueue 等待事件已经出现在TOP 5 中了,虽然发生等待的次数不多,但是等待时间却是相当长的了。借这个机会,把enqueue 等待事件整理如下:
- Enqueue 有3个参数:
1. P1 表示Lock type、mode 比如,P1RAW的值为54580006,其中,54表示的是T,58 表示的为X,6表示的专用锁; 我们也可以用
SELECT chr(to_char(bitand(p1,-16777216))/16777215)||
chr(to_char(bitand(p1, 16711680))/65535) "Lock",
to_char( bitand(p1, 65535) ) "Mode"
FROM v$session_wait
WHERE event = 'enqueue' ;
来查询当前发生enqueue 等待事件的Lock mode,该值对应着V$lock 中的 lock type
2. P2、P3 代表 Enqueue name 的ID1 和 ID2,分别对应着V$Lock 中的 ID1 和 ID2 - 大多数情况下,Enqueue 的等待时间为3秒
- 在v$Lock 中,request =0 表示的是 Holder,>0 表示的是 waiter
- 确定 Enqueue 的性能:
1. 我们可以查询 v$sysstat 来查看 enqueue 等待
select * from v$sysstata where class = 4
2. 对于 9i,我们可以查询:
SELECT eq_type "Lock",
total_req# "Gets",
total_wait# "Waits",
cum_wait_time
FROM V$enqueue_stat
WHERE Total_wait# > 0 ;
3. 对于 8i,我们可以查询:
SELECT ksqsttyp "Lock",
ksqstget "Gets",
ksqstwat "Waits"
FROM X$KSQST where KSQSTWAT > 0;
根据这两个sql ,我们来确定整个系统中的enqueue的等待情况 - 几个普遍存在的 Lock mode:
TX:事务锁 Note 62354.1; 在以下情况下发生: 1) Another session is locking the requested row. 2) When two sessions tries to insert the same unique key into a table (none of them has done a COMMIT), then the last session is waiting for the first one to COMMIT or ROLLBACK. 3) There are no free ITL (Interested Transaction List) in the block header (increase INI_TRANS och PCT_FREE for the segment).
TM:DML enqueue, 一般当外键没有建立索引的时候产生,Note 38373.1,Note 33453.1
ST:space management enqueue,当系统存在小碎片,或者存在大量的sort 的时候产生 Note 33567.1
JQ:Job queue
UL:user lock,当用户 DBMS_LOCK.REQUEST 时产生 - Enqueue 的解决:
1. 有的时候 db_cache_size 太大,或者 PGA 太小,会导致 Enqueue 的竞争
2.

机遇像个小偷,到来时无声无息,走时你却损失惨重