oracle 锁表 (在OS级杀死进程)
关闭数据库
SQL>shutdown immediate
关闭数据库,以确保杀死所有未断的User Session
当实例无法关闭无法使用shutdown immediate关闭时,可使用shutdown abort关闭实例,但关闭后应startup并再次使用shutdown immediate关闭实例,保证Database的同步
当在oracle下kill oracle进程后,sid被标记为Killed,但锁表仍未释放时,就在OS级杀进程。
主要步骤如下:
1)
select s.PROCESS,
s.SID,
s.SERIAL#,
b.object_name,
b.subobject_name,
a.LOCKED_MODE,
s.OSUSER,
s.LOGON_TIME,
s.MACHINE,
s.PROGRAM
from v$locked_object a, dba_objects b, v$session s
where a.OBJECT_ID = b.object_id
and a.SESSION_ID = s.SID
2)
alter system kill session 'SID,SERIAL#';
3)
此时如果oracle会话被标记为killed,但仍然锁住表,则需要根据SPID到OS系统中杀相应的oracle进程
查询spid的语句如下:
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=此处为上面查出的SID
4) kill -9 spid
查看当前user的serial#和sid
select sid, serial#, status from v$session where audsid=userenv('sessionid');
查看当前user的spid
select spid from v$process p join v$session s on p.addr=s.paddr and s.audsid=userenv('sessionid');
查看当前用户的trace file路径:
select p.value || '\' || t.instance || '_ora_' || ltrim(to_char(p.spid,'fm99999')) || '.trc'
from v$process p, v$session s, v$parameter p, v$thread t
where p.addr = s.paddr and s.audsid = userenv('sessionid') and p.name = 'user_dump_dest';