一、查看锁表语句

SELECT
	sess.sid,
	sess.serial#,
	lo.oracle_username, -- 登陆账号名称
	lo.os_user_name,    -- 登录电脑名称
	ao.object_name,     -- 被锁表名
	lo.locked_mode      -- 死锁级别
FROM
	v$locked_object lo,
	dba_objects ao,
	v$session sess 
WHERE
	ao.object_id = lo.object_id 
	AND lo.session_id = sess.sid;

死锁级别:

级别描述
0none
1null 空
2Row-S 行共享(RS):共享表锁
3Row-X 行专用(RX):用于行的修改
4Share 共享锁(S):阻止其他DML操作
5S/Row-X 共享行专用(SRX):阻止其他事务操作
6exclusive 专用(X):独立访问使用

二、解锁语句

alter system kill session '68,51'; -- 分别为SIDSERIAL#号

三、查看引起锁表的Sql语句

SELECT
	A.USERNAME,
	A.MACHINE,
	A.PROGRAM,
	A.SID,
	A.SERIAL#,
	A.STATUS,
	C.PIECE,
	C.SQL_TEXT 
FROM
	V$SESSION A,
	V$SQLTEXT C 
WHERE
	A.SID IN ( SELECT DISTINCT T2.SID FROM V$LOCKED_OBJECT T1, V$SESSION T2 WHERE T1.SESSION_ID = T2.SID ) 
	AND A.SQL_ADDRESS = C.ADDRESS ( + ) 
ORDER BY
	C.PIECE;

更多推荐