oracle-锁
-- 1.
SELECT l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
l.os_user_name,
s.machine,
s.terminal,
o.object_name,
s.logon_time,
p.SPID ,
'alter system kill session '''|| l.session_id||','|| s.serial# ||''';' --杀进程sql
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
ORDER BY sid, s.serial#;
-----2.
select object_name,machine,s.sid,s.serial#
from v$locked_object l,dba_objects o ,v$session s
where l.object_id = o.object_id and l.session_id=s.sid;
2.下面的语句用来杀死一个进程:
alter system kill session '24,111'; (其中24,111分别是上面查询出的sid,serial#)
【注】以上两步,可以通过Oracle的管理控制台来执行。
3.如果利用上面的命令杀死一个进程后,进程状态被置为"killed",但是锁定的资源很长时间没有被释放,那么可以在os一级再杀死相应的进程(线程),首先执行下面的语句获得进程(线程)号:
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=15 (24是上面的sid)
4.在OS上杀死这个进程(线程):
1)在unix上,用root身份执行命令:
#kill -9 12345(即第3步查询出的spid)
select distinct s1.* from V$DB_OBJECT_CACHE oc,
v$object_dependency od,
dba_kgllock w,
v$session s1
where oc.name = 'PCK_SEB_MGR'
and od.TO_OWNER = oc.OWNER
and od.TO_NAME = oc.NAME
and od.TO_ADDRESS = w.kgllkhdl
and w.kgllkuse = s1.SADDR;
--1.
SELECT S.USERNAME,
S.OSUSER,
S.SID,
S.SERIAL#,
P.SPID,
'alter system kill session ''' || S.SID || ',' || S.SERIAL# || ''';' --杀进程sql
FROM V$SESSION S, V$PROCESS P
WHERE S.PADDR = P.ADDR
AND S.USERNAME IS NOT NULL
and s.USERNAME = 'EIP'
order by s.SID;
--alter system kill session '100,43596';
--2.
select a.spid, b.sid, b.serial#, b.username
from v$process p, v$session s
where p.addr = s.paddr
and s.status = 'KILLED';
--sid:表示要杀死的进程属于的实例名 --thread:是要杀掉的线程号,即第3步查询出的spid。
--orakill sid thread
--orakill 162 5820
--C:\Users\ThinkPad>orakill xx/xx@wl 162 3112;
-------------------------
Oracle的KILL锁表及清除session方法
http://blog.sina.com.cn/s/blog_7134b6f301011q3z.html
Oracle中查看表是否被锁
http://blog.163.com/kangle0925%40126/blog/static/277581982011101661720386/
ORACLE中的被锁的表 http://blog.sina.com.cn/s/blog_713978a50100q3le.html