一般情況下,在殺一個會話的時候,直接執行alter system kill session ‘sid,serial#’;
Administrator's Guide說,當session是active的時候,alter system kill session 只是將session標識為killed
或者pseudo狀態,並不會釋放session持有的資源,所以我們在執行完alter system kill session 后,看會話還
是一直存在。
這種情況下可以使用 immediate選項,強制立即Kill會話,如下:
SQL> alter system kill session '3964,51752' immediate;
SQL Language Reference 里對Immediate的解釋是:IMMEDIATE Specify IMMEDIATE to instruct Oracle
Database to roll back ongoing transactions, release all session locks, recover the entire session state,
and return control to you immediately.
另外我們也可以使用alter system disconnect session
The POST_TRANSACTION setting allows ongoing transactions to complete before the session is disconnected.
If the session has no ongoing transactions, then this clause has the same effect described for as KILL SESSION.
The IMMEDIATE setting disconnects the session and recovers the entire session state immediately, without
waiting for ongoing transactions to complete.
-
If you also specify
POST_TRANSACTIONand the session has ongoing transactions, then theIMMEDIATEkeyword is ignored. -
If you do not specify
POST_TRANSACTION, or you specifyPOST_TRANSACTIONbut the session has no ongoing transactions, -
then this clause has the same effect as described for
KILLSESSIONIMMEDIATE. -
ORACLE建議的DCD解決方法
- 修改sqlnet.ora文件,新增expire_time=x(單位是分鍾)
- 通過ALTER PROFILE DEFAULT LIMIT IDLE_TIME x; 命令修改,重啟后生效。
通過OS殺進程終止會話
SELECT spid, osuser, s.program, schemaname FROM gv$process p, gv$session s WHERE p.addr = s.paddr;
- UNIX
kill -9 5745
ps -ef | grep pmon_$ORACLE_SID | awk '{print $2}' | xargs kill –9 #kill 一批會話
2. WINDOWS
orakill <instance_name> <spid>
如果會話已經在DB里killed,上面的SQL已經查不出spid,可以用下面的SQL查出SPID
select addr, pid, spid
FROM v$process p
where addr in (select p.addr
from v$process p
where pid <> 1
minus
select s.paddr from v$session s)


