Oracle kill inactive 线程

                                          
[sql] view plain copy print ?
  1. CREATE OR REPLACE PROCEDURE "KILL_SESSION" AS  
  2.         v_sid number;  
  3.         v_serial number;  
  4.                 killer varchar2(1000);  
  5.         CURSOR cursor_session_info is select sid,serial# from v$session where type!='BACKGROUND' and status='INACTIVE' and last_call_et>2700 and username='STPT' and machine='wonders_svr2';  
  6. BEGIN  
  7.         open cursor_session_info;  
  8.         loop  
  9.                 fetch cursor_session_info into v_sid,v_serial;  
  10.                 exit when cursor_session_info%notfound;  
  11.   
  12.                                 killer:='alter system disconnect session '''||v_sid||','||v_serial||''' post_transaction immediate';  
  13.                                                                 execute immediate killer;  
  14.                                         end loop;  
  15.                 dbms_output.PUT_LINE(cursor_session_info%rowcount||' users with idle_time>2700s have been killed!');  
  16.                 close cursor_session_info;  
  17. END;  


[sql] view plain copy print ?
  1. begin  
  2.   -- Call the procedure  
  3.   kill_session;  
  4. end;  

使用DBA用户 创建存储过程 并 执行,否则无法在procedure中访问 v$session

select machine,username,count(*) from gv$session group by machine,username

你可能感兴趣的:(oracle)