Kill ORACLE session 12c

Asked

Viewed 69 times

1

good morning. I would like to run a command to kill sessions on ORACLE 12C but the only command I know is ALTER SYSTEM KILL SESSION 'sid, serial, @instancia' IMMEDIATE;

But I wanted to kill specific sessions without typing SID and SERIAL always, ex:

WHERE machine LIKE 'BOA BOASRV120'
AND username LIKE 'CONSINCO'
AND PROGRAM = 'w3wp.exe'

Kill all sessions that fall under that WHERE above.

These sessions get INACTIVE status and wanted to kill them to be as 'KILLED';

Is there a way? Thank you

1 answer

1


You can build an anonymous block that basically searches your sessions, mounts the command and executes. Behold:

BEGIN     
 FOR reg in (SELECT 'alter system kill session ''' || ses.sid || ',' || ses.serial# ||''''  cmd
               FROM v$session ses
              WHERE machine LIKE 'BOA\BOASRV120'
                AND username LIKE 'CONSINCO'
                AND program = 'w3wp.exe') LOOP                
     EXECUTE IMMEDIATE reg.cmd;     
 END LOOP; 
END;
  • Thank you very much, helped too much - I circled him in hand , filtering 01 session only and killed! To turn this code into a Procedure just need to run the command "Create or Replace Procedure "name_tal" as (code) or I need to pass a parameter to work when I call it with call or exec? I want to put it in a Query View editor, so the user just click on a button and kill the stuck users, so he doesn’t even have access to code or anything.

  • You can transform yes. You don’t need parameters, unless you actually wanted to parameterize something in the session search... If the answer helped you is the case mark an answer as accepted

Browser other questions tagged

You are not signed in. Login or sign up in order to post.