Database

Script to kill user sessions in Oracle

steloflute 2013. 9. 13. 23:30

http://bukhantsov.org/2011/09/script-to-kill-user-sessions/

 

http://www.oracle-base.com/articles/misc/killing-oracle-sessions.php

 

ALTER SYSTEM DISCONNECT SESSION

The ALTER SYSTEM DISCONNECT SESSION syntax is an alternative method for killing Oracle sessions. Unlike the KILL SESSION command which asks the session to kill itself, the DISCONNECT SESSION command kills the dedicated server process (or virtual circuit when using Shared Sever), which is equivalent to killing the server process from the operating system. The basic syntax is similar to the KILL SESSION command with the addition of the POST_TRANSACTION clause. The SID and SERIAL# values of the relevant session can be substituted into one of the following statements.

SQL> ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' POST_TRANSACTION;
SQL> ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' IMMEDIATE;

The POST_TRANSACTION clause waits for ongoing transactions to complete before disconnecting the session, while the IMMEDIATE clause disconnects the session and ongoing transactions are rolled back immediately.

The POST_TRANSACTION and IMMEDIATE clauses can be used together, but the documentation states that in this case the IMMEDIATE clause is ignored. In addition, the syntax diagram suggests both clauses are optional, but in reality, one or both must be specified or you receive an error.

SQL> alter system disconnect session '30,7';
alter system disconnect session '30,7'
                                     *
ERROR at line 1:
ORA-02000: missing POST_TRANSACTION or IMMEDIATE keyword

SQL>

This command means you should never need to switch to the operating system to kill sessions, which reduces the chances of killing the wrong process.

 

 

 

'Database' 카테고리의 다른 글

Oracle plan 관련  (0) 2013.10.28
(Oracle) dictionary 조회  (0) 2013.09.13
(Oracle) Beware the /var/tmp/.oracle Hidden Directory!  (0) 2013.09.04
(Oracle) ANALYZE (통계정보 생성)  (0) 2013.09.02
Convert Unix Timestamp to Oracle data format  (0) 2013.08.26