

SQL> alter system kill session immediate Īnd terminated user session will get message in sqlplus that "your session has been killed" in Oracle RAC instance. OR optionally you can use following command to kill session in Oracle RAC. SQL> select sid,serial#,inst_id from gv$session where machine='GPTWORKGROUP' Here is example to kill or terminate active session from Oracle RAC database or instance.

#Oracle kill session query serial number#
After identifying target session from gv$session we need command "alter system kill session" with session identifier (sid), serial number (serial#) and instance number of Oracle RAC (instance_no). Because only gv$session contains rac instance identifier column. We use v$session for indetifying target session to kill in non-rac database.Here in Oracle RAC instance we should need to check and identify session using gv$session. It is very simple way to kill session using command line of Oracle RAC instance: Using SQL*Plus (kill session with alter system command): First oracle RAC DBA should need to identify which session has be killed and in which instance contains said target session. Oracle RAC database contains one or more instances. Some basic syntax is changed for killing session in Oracle RAC instance. While you are providing remote dba services and you require to kill session then you need to perform this task using command line only. At this moment remote Oracle DBA should need to terminate session/process called as murder of session. In various critical situations Oracle DBA has to decide to kill existing session or kill the background process of Oracle. These all steps can be done with Oracle Sql developer tool also.By Gitesh Trivedi / 2009-2010 / Published in Oracle DBA Tips Now if we execute any sql on killed session ,it will throw error SQL> select * from dual Now he knows from last_call_et column,he wants to kill the session (7277,51382).So he can execute the kill_session command as exec sys.kill_session( 7277,51382 ) So he can execute the below query in the second session SQL> select sid,serial# ,last_call_et from V$session where username='HR' Now suppose user HR wants to kill the first session. For this I created two session with the user HR with sqlplus utility Session 1 I execute a small test to demonstrate the procedure usage so that there is no doubt and developers can use this procedure flawlessly. They will not be able to kill any other user session and will get error message if he tries to execute that. Now all user has the access to this Procedure and They can kill there own session only. SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER')
#Oracle kill session query code#
If you want to deploy the code where in any user can use the procedure the kill its own session, we can execute below steps CREATE OR REPLACE PROCEDURE sys.kill_session(p_sid NUMBER, p_serial NUMBER) ORA-20002: Unauthorized Attempt to Kill a Non User Session has been Blocked. ORA-20001: Session has Expired or Invalid sid/serial Arguments PassedīEGIN apps.kill_session(7522,58115) END He will not be able to kill any session not owned and will get the error message He can identify the session to be killed and then execute the command set serveroutput on User can get the session information using the below query select sid,serial#, Username ,module from v$session where username='SCOTT' RAISE_APPLICATION_ERROR(-20002,'Unauthorized Attempt to Kill a Non User Session has been Blocked.') Ĭreate or replace procedure kill_session( p_sid in number, p_serial# in number) RAISE_APPLICATION_ERROR(-20001,'Session has Expired or Invalid sid/serial Arguments Passed') IF v_user IN ('SCOTT') THEN -the list can be extendedĮXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION ''' || p_sid || ',' || p_serial || ''''

Suppose we want to give kill session access to the user SCOTT to kill its own session CREATE OR REPLACE PROCEDURE sys.kill_session(p_sid NUMBER, p_serial NUMBER) This way developer will be more independent and DBA will also get time to work on other priorities

This bottleneck can be achieved by creating a procedure and then giving execute on that procedure to the user. We can give alter system privilege but it will other grants also which Oracle DBA don’t want. We dont have any privilege like alter system kill session which can be given to the user. They want the oracle kill own session privilege. Often developers ask how we can kill our own session as they dont want to wait for the DBA to respond and kill.
