您的位置:首页 > 数据库

utllockt.sql来获取当前db中的锁情况

2016-01-29 00:00 831 查看
下面是一个完整的演示过程:
SQL> @ ?/rdbms/admin/catblock.sql
View created.

Synonym created.

Grant succeeded.
drop synonym DBA_LOCKS
*
ERROR at line 1:
ORA-01434: private synonym to be dropped does not exist

drop view DBA_LOCKS
*
ERROR at line 1:
ORA-00942: table or view does not exist

View created.

Synonym created.

Grant succeeded.

Synonym created.

View created.

Synonym created.

Grant succeeded.

View created.

Synonym created.

Grant succeeded.

View created.

Synonym created.

Grant succeeded.

View created.

Synonym created.

Grant succeeded.

View created.

Synonym created.

Grant succeeded.
SQL> show user
USER is "SYS"
SQL> @ ?/rdbms/admin/utllockt.sql
drop table lock_holders
*
ERROR at line 1:
ORA-00942: table or view does not exist

Table created.
drop table dba_locks_temp
*
ERROR at line 1:
ORA-00942: table or view does not exist

Table created.

1 row created.

Commit complete.

Table dropped.

1 row created.

Commit complete.

WAITING_SESSION LOCK_TYPE MODE_REQUESTED MODE_HELD LOCK_ID1 LOCK_ID2
----------------- ----------------- -------------- -------------- ----------------- -----------------
147 None
141 Transaction Exclusive Exclusive 262156 211

Table dropped.
SQL> select * from dba_waiters;
WAITING_SESSION HOLDING_SESSIONLOCK_TYPE MODE_HELD MODE_REQUESTED LOCK_ID1 LOCK_ID2
--------------- --------------- -------------------------- ---------------- ------------------- ---------- ----------
141 147 Transaction Exclusive Exclusive 262156 211

SQL> select * from DBA_BLOCKERS;
HOLDING_SESSION
---------------
147
从上面的信息,可以看出当前db中,session 147 阻塞了session 141,其中147持有X 模式锁。

下面来看下enqueue的dump情况,如下:
*** 2011-02-13 18:38:13.949
===================================================
ENQUEUES
--------
Active: lock: (nil), resource: (nil)
Global: name: ROGER
Hash: length: 375, at: 0x2947cf8c
[2947cf8c,2947cf8c] [2947cfa4,2947cfa4] [2947cfbc,2947cfbc]
[2947cfd4,2947cfd4] [2947cfec,2947cfec] [2947d004,2947d004]
.....省略部分信息
[2947f26c,2947f26c] [2947f284,2947f284] [2947f29c,2947f29c]
res identification NUL SS SX S SSX X md link
owners converters waiters
-------------------------------------------------------------------------
0x29467c74 XR-00000004-00000000 1 0 0 0 0 0 2 [2947e984,2947e984]
[29434240,29434240] [29467c8c,29467c8c] [29467c84,29467c84]
lock que owner session hold wait ser link
----------------------------------------------------------------------
0x29434238 OWN 0x29f25f58 0x29f25f58 (165) NULL NLCK 1 [29467c7c,29467c7c]
0x29467f34 CF-00000000-00000000 0 1 0 0 0 0 4 [2947ef54,2947ef54]
[2943429c,2943429c] [29467f4c,29467f4c] [29467f44,29467f44]
lock que owner session hold wait ser link
.........省略部分信息
----------------------------------------------------------------------
0x28a0aefcOWN 0x29f0fa280x29f0fa28 (147) XNLCK 123 [29469034,29469034]
0x29434460 WAT 0x29f08318 0x29f08318 (141) NLCK X 61 [2946903c,2946903c]
0x294690dc PW-00000001-00000000 U 0 0 1 0 0 0 8 [2947d1b4,2947d1b4]
[294342f8,294342f8] [294690f4,294690f4] [294690ec,294690ec]
lock que owner session hold wait ser link
----------------------------------------------------------------------
0x294342f0 OWN 0x29f28708 0x29f28708 (167) SX NLCK 1 [294690e4,294690e4]
0x29469c9c TA-00000006-00000001 0 0 0 0 0 1 40 [2947dc34,2947dc34]
[294343b0,294343b0] [29469cb4,29469cb4] [29469cac,29469cac]
lock que owner session hold wait ser link
----------------------------------------------------------------------
0x294343a8 OWN (null) X NLCK [29469ca4,29469ca4]
0x2946a5f4 TS-00000003-00000001 0 0 1 0 0 0 8 [2947dd9c,2947dd9c]
[29434800,29434800] [2946a60c,2946a60c] [2946a604,2946a604]
lock que owner session hold wait ser link
----------------------------------------------------------------------
0x294347f8 OWN 0x29f237a8 0x29f237a8 (163) SX NLCK 1 [2946a5fc,2946a5fc]
0x2946ba4c TM-0000cac0-00000000 U 0 0 2 0 0 0 8 [2947eb1c,2947eb1c]
[289c661c,289c6570] [2946ba64,2946ba64] [2946ba5c,2946ba5c]
lock que owner session hold wait ser link
----------------------------------------------------------------------
0x289c6614 OWN 0x29f08318 0x29f08318 (141) SX NLCK 61 [289c6570,2946ba54]
0x289c6568 OWN 0x29f0fa28 0x29f0fa28 (147) SX NLCK 123 [2946ba54,289c661c]
上面红色的部分一目了然 不做过多描述
下面我们来看看上面提到的几个视图 下面是其定义:
CREATE OR REPLACE FORCE VIEW "SYS"."DBA_WAITERS" ("WAITING_SESSION", "HOLDING_
SESSION", "LOCK_TYPE", "MODE_HELD", "MODE_REQUESTED", "LOCK_ID1", "LOCK_ID2") AS
select /*+ordered */ w.sid
,s.ksusenum
,decode(r.ksqrsidt,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distributed Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table',
r.ksqrsidt)
,decode(l.lmode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', &nbs
3ff0
p; /* X */
l.lmode)
,decode(bitand(w.p1,65535),
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
to_char(bitand(w.p1,65535)))
,r.ksqrsid1, r.ksqrsid2
from v$session_wait w, x$ksqrs r, v$_lock l, x$ksuse s
where w.wait_Time = 0
and w.event like 'enq:%'
and r.ksqrsid1 = w.p2
and r.ksqrsid2 = w.p3
and r.ksqrsidt = chr(bitand(p1,-16777216)/16777215)||
chr(bitand(p1,16711680)/65535)
and l.block = 1
and l.saddr = s.addr
and l.raddr = r.addr
and s.inst_id = userenv('Instance');

CREATE OR REPLACE FORCE VIEW "SYS"."DBA_BLOCKERS" ("HOLDING_SESSION") AS
select /*+ordered */ distinct s.ksusenum holding_session
from v$session_wait w, x$ksqrs r, v$_lock l, x$ksuse s
where w.wait_Time = 0
and w.event like 'enq:%'
and r.ksqrsid1 = w.p2
and r.ksqrsid2 = w.p3
and r.ksqrsidt = chr(bitand(p1,-16777216)/16777215)||
chr(bitand(p1,16711680)/65535)
and l.block = 1
and l.saddr = s.addr
and l.raddr = r.addr
and s.inst_id = userenv('Instance');
其中关联了2个x$表,下面是该2 x$表的含义:
[K]ernel [S]ervice en[Q]ueue [RE]source
[K]ernel [S]ervice [U]ser [SE]ssion

最后补充一句,其实从上面的定义,我们又能提取出1个检测锁的脚本了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle lock