понедельник, 31 июля 2017 г.

Determine How Long a Session has been Idle using v$session

Following SQL using information from LAST_CALL_ET:
  1. select s.*
  2. --select 'ALTER SYSTEM KILL SESSION ''' || s.sid || ',' || s.serial# || ''' IMMEDIATE;' kill_serial_sid
  3. from (
  4. SELECT s.sid,s.serial#,s.username
  5. ,s.status
  6. ,substr(s.machine,1,10)
  7. ,s.osuser,s.module
  8. ,to_char(logon_time, 'mm/dd/yy hh24:mi:ss') logon_time
  9. -- idle time
  10. ,to_dsinterval(
  11. -- days separately
  12. substr('0'||trunc(last_call_et/86400),-2,2) || ' ' ||
  13. -- hours
  14. substr('0'||trunc(mod(last_call_et,86400)/3600),-2,2) || ':' ||
  15. -- minutes
  16. substr('0'||trunc(mod(mod(last_call_et,86400),3600)/60),-2,2) || ':' ||
  17. --seconds
  18. substr('0'||mod(mod(mod(last_call_et,86400),3600),60),-2,2)
  19. ) idle_time
  20. FROM v$session s, v$process p
  21. WHERE s.username IS NOT NULL
  22. -- use outer join to show sniped sessions in
  23. -- v$session that don''t have an OS process
  24. AND p.addr(+) = s.paddr
  25. ) s
  26. where 1 = 1
  27. and s.status = 'INACTIVE'
  28. and s.idle_time >= to_dsinterval('1 00:00:00')
  29. ORDER BY idle_time desc;
Note: LAST_CALL_ET - If the session STATUS is currently ACTIVE, then the value represents the elapsed time in seconds since the session has become active.
If the session STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.

Search Idle Sessions using filter in Enterprise Manager

You can specify search criteria using WHERE clause

as following:
  1. 1 = 1
  2. and username IS NOT NULL
  3. and status = 'INACTIVE'
  4. and to_dsinterval(
  5. -- days separately
  6. substr('0'||trunc(last_call_et/86400),-2,2) || ' ' ||
  7. -- hours
  8. substr('0'||trunc(mod(last_call_et,86400)/3600),-2,2) || ':' ||
  9. -- minutes
  10. substr('0'||trunc(mod(mod(last_call_et,86400),3600)/60),-2,2) || ':' ||
  11. --seconds
  12. substr('0'||mod(mod(mod(last_call_et,86400),3600),60),-2,2)
  13. ) >= to_dsinterval('1 00:00:00')