共计 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 行业资讯频道!