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
把上面查询结果执行下就可以解锁