殺掉長期inactive的程式

lsm_3036發表於2011-04-07

給大家一個殺掉長期不活動程式的語句

CREATE OR REPLACE PROCEDURE "KILL_SESSION" AS
        v_sid number;
        v_serial number;
                killer varchar2(1000);
        CURSOR cursor_session_info is select sid,serial# from v$session where type!='BACKGROUND' and status='INACTIVE' and last_call_et>2700 and username='NACECCMS28';
BEGIN
        open cursor_session_info;
        loop
                fetch cursor_session_info into v_sid,v_serial;
                exit when cursor_session_info%notfound;
                               
                                killer:='alter system disconnect session '''||v_sid||','||v_serial||''' post_transaction immediate';
                                                                execute immediate killer;
                                        end loop;
                dbms_output.PUT_LINE(cursor_session_info%rowcount||' users with idle_time>2700s have been killed!');
                close cursor_session_info;
END;
/
#這樣做其實還是治標不治本,最好能夠解決連線池自動釋放idle程式的問題
#last_call_et指的是空閒空間較長的連線

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16978544/viewspace-691848/,如需轉載,請註明出處,否則將追究法律責任。

相關文章