Oracle锁表查询和解锁方法
qhzhen9 2019-05-22 10:07:07 8822 收藏 7
展开
我们这里一般用的PL/SQL,总是无意间把表锁住,所以我今天就整理了一下简单的解锁和查询锁表的方法;
一、首先PL/SQL要以管理员的账号(system/admin等)登录,管理员的账号和密码根据个人设置而来,连接为一般选择Normal,也可选择SYSDBA;
二、相关SQL语句:
--以下几个为相关表
SELECT*FROMv$lock;
SELECT*FROMv$sqlarea;
SELECT*FROMv$session;
SELECT*FROMv$process;
SELECT*FROMv$locked_object;
SELECT*FROMall_objects;
SELECT*FROMv$session_wait;
--查看被锁表信息
SQL > 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;
--杀掉锁表进程
SQL > alter system kill session ‘68,51‘;--分别为SID和SERIAL#号
--查看数据库引起锁表的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;
————————————————
版权声明:本文为CSDN博主「qhzhen9」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_38819293/java/article/details/86526696