Oracle的锁分为两大类,一类就是极为常见的DML事务锁,是为保障数据库系统数据一致性而存在的锁,其中分共享锁、排它锁等,不同的DBMS对这类锁的实现参差不齐;另一大类锁就是DDL级锁,这类锁一般出现在开发或发布时候,一旦出现比较棘手。下面就两类所的锁查找和灭杀做一个阐述。
1、查找DML锁
select p.spid,
s.sid,
s.serial#,
s.username,
s.machine,
s.osuser,
s.terminal,
s.module,
s.program,
o.object_name
from v$session s, v$process p, v$locked_object l, all_objects o
where s.paddr = p.addr
and s.sid = l.session_id
and l.object_id = o.object_id
order by s.logon_time desc;
2、查找DDL锁
select d.spid,
c.sid,
c.serial#,
c.username,
c.machine,
c.osuser,
c.terminal,
c.module,
c.program,
a.object,
b.locks
from v$access a, v$db_object_cache b, v$session c, v$process d
where a.object = b.name
and a.owner = b.owner
and a.sid = c.sid
and c.paddr = d.addr
order by c.logon_time desc;
3、根据sid、serial#或spid灭杀锁
alter system kill session 'sid,serial#';
或者在操作系shell下执行
$kill -9 spid
或斯文点的办法
$orakill instance spid;
其中sid,serial#,spid是语句查出的数值,instance是数据的实例名称。