日期:2014-05-17  浏览次数:21034 次

Oracle中查询锁的数量
RT
如何使用SQL语句查询

------解决方案--------------------
查询锁定的表:
select s.audsid AUDSID,
s.SID,
s.SERIAL#,
l.os_user_name "OS Username",
l.oracle_username "Username",
l.process "Process",
p.spid "SPID",--进程ID
o.owner "Owner",
o.object_name "Object",
decode(l.locked_mode, 1,'No Lock', 2,'Row Share', 3,'Row Exclusive',
4,'Share', 5,'Share Row Excl', 6,'Exclusive',null) "Lock Mode",
substr(s.status,1,8) "Status"
from v$locked_object l, all_objects o, v$session s, v$process p
where l.object_id = o.object_id
and l.session_id = s.sid
and s.paddr = p.addr
and s.status <> 'KILLED';

kill session:
alter system kill session 'sid,serial#';
kill process:
KILL -9 'SPID'
------解决方案--------------------
SQL code

--當前會話鎖的數量
select count(*) from v$session s,v$lock l where s.sid=l.sid;

------解决方案--------------------
1. 查看被锁的表
SELECT p.spid, a.serial#, c.object_name, b.session_id, b.oracle_username,
b.os_user_name
FROM v$process p, v$session a, v$locked_object b, all_objects c
 WHERE p.addr = a.paddr AND a.process = b.process
AND c.object_id = b.object_id

2. 查看是哪个进程锁的 
SELECT sid, serial#, username, osuser FROM v$session where osuser = 'tangpj'

2. 查看是哪个进程锁的 
SELECT sid, serial#, username, osuser,'ALTER SYSTEM KILL SESSION '''||SID||','|| SERIAL#||''';' 
 FROM v$session where osuser = 'Administrator'

3. 杀掉这个进程 alter system kill session 'sid,serial#';