溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ORACLE中alter system kill session怎么實(shí)現(xiàn)立即結(jié)束一個(gè)會話

發(fā)布時(shí)間:2021-11-09 09:45:46 來源:億速云 閱讀:1795 作者:小新 欄目:關(guān)系型數(shù)據(jù)庫

這篇文章主要為大家展示了“ORACLE中alter system kill session怎么實(shí)現(xiàn)立即結(jié)束一個(gè)會話”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“ORACLE中alter system kill session怎么實(shí)現(xiàn)立即結(jié)束一個(gè)會話”這篇文章吧。

一般情況下,在殺掉一個(gè)會話的時(shí)候,直接執(zhí)行alter system kill session ‘sid,serial#’; 隨后進(jìn)行查詢發(fā)現(xiàn),被KILL掉的會話狀態(tài)變?yōu)镵ILLED狀態(tài),并沒有立即結(jié)束,稍后再次查詢該會話,確認(rèn)已經(jīng)結(jié)束。如果希望立即結(jié)束一個(gè)會話,如何處理?

經(jīng)過查詢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.

當(dāng)session是active的時(shí)候,alter system kill session 只是將session標(biāo)識為killed狀態(tài),并不會釋放session持有的資源,所以我們在執(zhí)行完alter system kill session 后,看會話還是一直存在,等待PMON進(jìn)程回收資源和釋放鎖等。

如果:
不加IMMEDIATE,僅僅是標(biāo)記該事務(wù)為中斷,等待PMON進(jìn)程來回收該SESSION所占用的資源及釋放鎖等;
加IMMEDIATE, 即在alter system kill session 'sid,serial,@sid' 后增加 immediate來實(shí)現(xiàn)立即結(jié)束會話。

以上是“ORACLE中alter system kill session怎么實(shí)現(xiàn)立即結(jié)束一個(gè)會話”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI