共計 1589 個字符,預計需要花費 4 分鐘才能閱讀完成。
這篇文章主要為大家展示了“ORACLE 中 alter system kill session 怎么實現立即結束一個會話”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓丸趣 TV 小編帶領大家一起研究并學習一下“ORACLE 中 alter system kill session 怎么實現立即結束一個會話”這篇文章吧。
一般情況下,在殺掉一個會話的時候,直接執行 alter system kill session‘sid,serial#’; 隨后進行查詢發現,被 KILL 掉的會話狀態變為 KILLED 狀態,并沒有立即結束,稍后再次查詢該會話,確認已經結束。如果希望立即結束一個會話,如何處理?
經過查詢 ORACLE DOC 得知
ORACLE DOC:
The KILL SESSION clause lets you mark a session as terminated, roll back ongoing transactions, release all session locks, and partially recover session resources. To use this clause, your instance must have the database open. Your session and the session to be terminated must be on the same instance unless you specify integer3.
If the session is performing some activity that must be completed, such as waiting for a reply from a remote database or rolling back a transaction, then Oracle Database waits for this activity to complete, marks the session as terminated, and then returns control to you. If the waiting lasts a minute, then Oracle Database marks the session to be terminated and returns control to you with a message that the session is marked to be terminated. The PMON background process then marks the session as terminated when the activity is complete.
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.
當 session 是 active 的時候,alter system kill session 只是將 session 標識為 killed 狀態,并不會釋放 session 持有的資源,所以我們在執行完 alter system kill session 后,看會話還是一直存在,等待 PMON 進程回收資源和釋放鎖等。
如果:
不加 IMMEDIATE,僅僅是標記該事務為中斷,等待 PMON 進程來回收該 SESSION 所占用的資源及釋放鎖等;
加 IMMEDIATE, 即在 alter system kill session sid,serial,@sid 后增加 immediate 來實現立即結束會話。
以上是“ORACLE 中 alter system kill session 怎么實現立即結束一個會話”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注丸趣 TV 行業資訊頻道!