Sunday, 13 December 2020

Oracle Session Kill Script - Session Management

 

To kill a session in Oracle, you can use the following sql/procedures. The SID and serial# can be collected from v$session.

alter system kill session 'SID, serial#';

 

To kill several sessions of a user, following PLSQL block can be used.

begin
   for i in (SELECT 'alter system kill session '''||SID||','||serial#||'''' as command FROM  
             v$session where username = 'USERNAME'
            )
   loop
      execute immediate i.command;
   end loop;
end;
/

 


To kill sessions of multiple user-specific sessions, following PLSQL block can be used.

begin
   for i in (SELECT 'alter system kill session '''||SID||','||serial#||'''' as command FROM  
             v$session where username in ('USERNAME_1', 'USERNAME_2')
            )
   loop
      execute immediate i.command;
   end loop;
end;
/


Find More Session Related Scripts here



No comments:

Post a Comment