Oracle锁表及解锁方法
1. 首先查看数据库中哪些表被锁了,找到session ID:
使用sql:
select b.owner,b.object_name,a.session_id,a.locked_mode
from v$locked_object a,dba_objects b
where b.object_id = a.object_id;
OWNER :数据表的所有者用户
OBJECT_NAME: 被锁住的表名
SESSION_ID: 会话ID
LOCKED_MODE: 锁级别
锁级别分为6级:
1级锁有:Select
2级锁有:Select for update,Lock For Update,Lock Row Share
3级锁有:Insert, Update, Delete, Lock Row Exclusive
4级锁有:Create Index, Lock Share
5级锁有:Lock Share Row Exclusive
6级锁有:Alter table, Drop table, Drop Index, Truncate table, Lock Exclusive
2.再执行该语句,查看会话id
select b.username,b.sid,b.serial#,logon_time
from v$locked_object a,v$session b
where a.session_id = b.sid order by b.logon_time;
3.杀会话
alter system kill session 'sid,serial#';
例子:
alter system kill session '20,30153'; -----这个是我刚才杀死会话前的执行语句
如果有ora-00031错误,则在后面加immediate;
alter system kill session '20,30153' immediate;
————————————————
还有一种简便快捷办法
select 'alter system kill session '''||sess.sid||','||sess.serial#||''';'
from v$locked_object lo,
dba_objects ao,
v$session sess
where ao.object_id = lo.object_id and lo.session_id = sess.sid
————————————————
版权声明:本文为CSDN博主「lichongxyz」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lichongxyz/article/details/126851107