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;

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐