Home » RDBMS Server » Server Utilities » Kill Inactive Session after 2 hours
Kill Inactive Session after 2 hours [message #71769] Wed, 08 January 2003 07:18 Go to next message
Harry
Messages: 17
Registered: March 2001
Junior Member
Can some body help in wrting the script for this to
KILL THE INACTIVE SESSION AFTER 2 HOURS ( if it is has inactive from last 2 hours or more.)

Thanks In Advance
Re: Kill Inactive Session after 2 hours [message #71771 is a reply to message #71769] Wed, 08 January 2003 09:16 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
beware!. test the script first.
-- i have commented the execute statement ( dynamic 
--sql) which will actually do the job. ( i cant kill my
-- users~!!!
SQL> ed
Wrote file afiedt.buf

  1  select        username,status,logon_time  from v$session
  2          where      status='INACTIVE' AND
  3*                    TO_CHAR(SYSDATE,'HH') - TO_CHAR(LOGON_TIME,'HH') >=2
SQL> /

USERNAME                       STATUS   LOGON_TIME
------------------------------ -------- --------------------
LAWSON                         INACTIVE 08-jan-2003 08:42:14
LAWSON                         INACTIVE 08-jan-2003 08:54:45
SQL> ed
Wrote file afiedt.buf

  1  create or replace procedure kill_session
  2  as
  3  cursor c1 is select        *  from v$session
  4          where      status='INACTIVE' AND
  5                     TO_CHAR(SYSDATE,'HH') - TO_CHAR(LOGON_TIME,'HH') >=2;
  6  begin
  7  for mag in c1 loop
  8     exit when c1%notfound;
  9     dbms_output.put_line('user to be killed: '||mag.username);
 10  -- execute immediate ('alter system kill session ('||mag.sid||','||mag.serial#||')');
 11     end loop;
 12* end;
SQL> /
Procedure created.

SQL> exec kill_session;
user to be killed: LAWSON
user to be killed: LAWSON

PL/SQL procedure successfully completed.

----------------------------------------------------------------------

i would prefer to do the same ,
by seeting up the profile, utilizing
IDLE_TIME & CONNECT_TIME 

Previous Topic: Urgent - Loading Data from Comma Sep File(CSV)
Next Topic: Cannot format columns in the control file
Goto Forum:
  


Current Time: Tue May 14 09:34:59 CDT 2024