V$LOCK

 

V$LOCK 视图查看当前系统中的锁 

Column             

Datatype

Description

ADDR

RAW(4 | 8)

Address of lock state object

KADDR

RAW(4 | 8)

Address of lock

SID

NUMBER

Identifier for session holding or acquiring the lock

TYPE

VARCHAR2(2)

Type of user or system lock

The locks on the user types are obtained by user applications. Any process that is blocking others is likely to be holding one of these locks. The user type locks are:

TM - DML enqueue

TX - Transaction enqueue

UL - User supplied

The system type locks are listed in Table 8-1. Be aware that not all types of locks are documented. To find a complete list of locks for the current release, query the V$LOCK_TYPEdata dictionary view, described on "V$LOCK_TYPE".

ID1

NUMBER

Lock identifier #1 (depends on type)

ID2

NUMBER

Lock identifier #2 (depends on type)

LMODE

NUMBER

Lock mode in which the session holds the lock:

 

0 - none

1 - null (NULL)

2 - row-S (SS)

3 - row-X (SX)

4 - share (S)

5 - S/Row-X (SSX)

6 - exclusive (X)

 

REQUST

NUMBER

Lock mode in which the process requests the lock:

0 - none

1 - null (NULL)

2 - row-S (SS)

3 - row-X (SX)

4 - share (S)

5 - S/Row-X (SSX)

6 - exclusive (X)

 

CTIME

NUMBER

Time since current mode was granted

BLOCK

NUMBER

A value of either 0 or 1, depending on whether or not the lock in question is the blocker.

 

V$LOCK 里的type 可以同过视图v$lock_type查看锁的具体含义在10.2.0.1 里有158种锁,到了11.2.01里 锁的种类增加到了202个锁

在官当里对 ID1和ID2的解释很模糊,到底ID1和ID2表示什么呢


根据锁的种类的不同ID1 和ID2所代表的意义不同,我们经常遇到的锁的种类摸过于TX 和TM锁,我们来看看具体含义吧

在TX锁:

ID1对应视图V$TRANSACTION中的XIDUSN字段和XIDSLOT字段。其中ID1的高16位为XIDUSN,低16位为XIDSLOT。其组成形式为: 0xRRRRSSSS ( RRRR = RBS number, SSSS = slot 

ID2对应视图V$TRANSACTION中的XIDSQN字段。以十进制表示该slot被重用的次数


 xidusn= selecttrunc(id1/power(2,16)) XIDUSN from dual

                           xidslot=select bitand(id1,65535) from dual

                           或 xidslot=select bitand(id1,to_number('ffff','xxxx') from dual )

 


在TM锁:

ID1对于与dba_object 里的object_id

ID2: 等于0


SQL> create table t1 as select * from emp where 0=1;
Table created.

SQL> insert into t1 select * From emp;
14 rows created.

SQL> select distinct sid from v$mystat;

       SID
----------
       159

另外开一个session:

SQL> select * From v$lock where sid=159;

ADDR KADDR SID TY        ID1  ID2  LMODE    REQUESTCTIME   BLOCK
-------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------
3D1C3F90 3D1C3FA8 159 TM      51373   0      3 0  1330
3D22541C 3D225538 159 TX     131090 259      6 0  1330


SQL> select XIDUSN,XIDSLOT,XIDSQN from V$TRANSACTION where XIDSQN=259;
    XIDUSN    XIDSLOT  XIDSQN
---------- ---------- ----------
2   18    259


SQL>  Select  trunc(131090/power(2,16))  XIDUSN from dual;
  XIDUSN
----------
2

SQL> select bitand(131090,65535) from dual;
BITAND(131090,65535)
--------------------
 18

SQL> select object_name from dba_objects where object_id='51373';
OBJECT_NAME
--------------------------------------------------------------------------------------------------------------------------------
T1


锁的视图:

 v$lock

  v$lock_type 

 dba_lock


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值