V$LOCK
ADDR 锁定状态对象地址
KADDR 锁地址
SID 会话id
ID1 锁标识符#1
ID2 锁标识符#2
LMODE 会话持有的锁模式(0~6)
REQUEST 进程请求的锁模式(0~6)
CTIME 当前模式的时间
ADDR 锁定状态对象地址
KADDR 锁地址
SID 会话id
ID1 锁标识符#1
ID2 锁标识符#2
LMODE 会话持有的锁模式(0~6)
REQUEST 进程请求的锁模式(0~6)
CTIME 当前模式的时间
BLOCK 为1代表阻碍者,表示正在阻碍其它会话
- --查找正在阻碍其它会话(阻碍者)的会话--sid为138的会话正在阻碍其它的会话
- SQL>SELECTt.ADDR,
- 2t.KADDR,
- 3t.SID,
- 4t.TYPE,
- 5t.ID1,
- 6t.ID2,
- 7t.LMODE,
- 8t.REQUEST,
- 9t.CTIME,
- 10t.BLOCK
- 11FROMv$lockt
- 12WHEREt.BLOCK=1
- 13ORDERBYt.CTIMEDESC;
- ADDRKADDRSIDTYPEID1ID2LMODEREQUESTCTIMEBLOCK
- ------------------------------------------------------------------------------------------
- 289E1F90289E1FA8138TM5143406010921
- 28A4917C28A49298138TX393262353605381
- SQL>
- --查找正在阻碍其它会话(阻碍者)的会话--sid为138会话的详细信息
- SQL>SELECTt1.SID,
- 2t1.SERIAL#,
- 3t1.USERNAME,
- 4t2.TYPE,
- 5t2.ID1,
- 6t2.ID2,
- 7t2.LMODE,
- 8t2.REQUEST,
- 9t2.CTIME,
- 10t2.BLOCK
- 11FROMv$sessiont1,v$lockt2
- 12WHEREt1.SID=t2.SID
- 13ANDt1.USERNAMEISNOTNULL--USERNAME为NULL代表oracle后台进程
- 14ANDt2.BLOCK=1
- 15ORDERBYt2.CTIMEDESC;
- SIDSERIAL#USERNAMETYPEID1ID2LMODEREQUESTCTIMEBLOCK
- ------------------------------------------------------------------------------------------------------------------
- 1382SYSTM5143406011221
- 1382SYSTX393262353605681
- --如果锁类型为(TYPE)为TM,v$lock.ID1代表锁定的对象id(dba_objects.OBJECT_ID).
- SQL>SELECTt.owner,t.object_nameFROMdba_objectstWHEREt.object_id=51434;
- OWNEROBJECT_NAME
- --------------------------------------------------------------------------------------------------------------
- SYST_LOCK
- /**如果锁类型为(TYPE)为TX:
- *v$lock.ID1代表v$transaction.XIDUSN和v$transaction.XIDSLOT,(ID1的高16位为XIDUSN,低16位为XIDSLOT)。
- *v$lock.ID2为v$transaction.XIDSQN。
- *
- *以下是ID1,ID2与v$transaction列的转换
- */
- SQL>SELECTs.XIDUSN,s.XIDSLOT,s.XIDSQNFROMv$transactionsWHEREs.XIDSQN=353;
- XIDUSNXIDSLOTXIDSQN
- ------------------------------
- 646353
- --ID1转换为v$transaction.XIDUSN和v$transaction.XIDSLOT,正好与上面sql相同结果
- SQL>SELECTtrunc(393262/power(2,16))XIDUSN,
- 2bitand(393262,to_number('ffff','xxxx'))+0XIDSLOT
- 3FROMdual;
- XIDUSNXIDSLOT
- --------------------
- 646
- SQL>
- --查找被阻塞(正在等待)会话执行的sql,
- SQL>SELECTt1.SID,
- 2t1.SERIAL#,
- 3t1.USERNAME,
- 4t2.CTIME,
- 5t2.TYPE,
- 6t2.REQUEST,
- 7t3.PIECE,
- 8t3.SQL_TEXT
- 9FROMv$sessiont1,v$lockt2,v$sqltextt3
- 10WHEREt1.SID=t2.SID
- 11ANDt1.USERNAMEISNOTNULL
- 12ANDt1.LOCKWAIT=t2.KADDR
- 13--ANDt3.SQL_ID=t1.SQL_ID
- 14ANDt3.ADDRESS=t1.SQL_ADDRESS
- 15ANDt3.HASH_VALUe=t1.SQL_HASH_VALUE
- 16ORDERBYt2.CTIMEDESC,t3.PIECE;
- SIDSERIAL#USERNAMECTIMETYPEREQUESTPIECESQL_TEXT
- ---------------------------------------------------------------------------------------------------------------------------
- 13152SYS3499TM40locktablet_lockinsharemode
- 15028SYS3036TX60updatetsettext='jerry'whereid=1
- --查看阻碍者阻塞了哪些会话
- SQL>SELECTt1.SID,
- 2t1.USERNAME,
- 3t1.BLOCKING_SESSION,
- 4t1.BLOCKING_SESSION_STATUS
- 5FROMv$sessiont1
- 6WHEREt1.LOCKWAITISNOTNULL
- 7ANDt1.BLOCKING_SESSION=138
- 8--ANDt1.USERNAMEISNOTNULL
- 9ORDERBYt1.SID;
- SIDUSERNAMEBLOCKING_SESSIONBLOCKING_SESSION_STATUS
- -------------------------------------------------------------------------------
- 131SYS138VALID--ACTIVE-SessioncurrentlyexecutingSQL
- 150SYS138VALID
- --kill会话,当确定了会话之后,可以kill,对于oracle进程要慎重
- SQL>altersystemkillsession'131,52';
- Systemaltered