ÔÚʵ¼ÊµÄÊý¾Ý¿âÓ¦ÓÃÖУ¬ÎÒÃǾ³£Óöµ½ÕâÑùÒ»¸öÎÊÌ⣬Á¬½Óµ½OracleÊý¾Ý¿âµÄÓû§ÔÚ×÷ÁËÒ»´Î²Ù×÷ºó£¬ÔÙҲûÓкóÐø²Ù×÷£¬µ«È´³¤Ê±¼äûÓкÍÊý¾Ý¿â¶Ï¿ªÁ¬½Ó¡£¶ÔÓÚÒ»¸öСÐ͵ÄÓ¦ÓÃϵͳÀ´½²£¬±¾ÉíµÄÁ¬½ÓÊýÄ¿¾ÍÓÐÏÞ£¬ÕâºÃÏñûÓÐʲôÑÏÖصĺó¹û£¬µ«Èç¹û¶ÔÓÚÒ»¸ö´óÐ͵ÄÊý¾Ý¿âÓ¦Óá£ÈçË°Îñ¡¢¹¤É̵ȣ¬Èç¹ûÊý¾Ý¿âµÄÁ¬½ÓÊýÄ¿ºÜ¶à£¬¶ÔÓÚÊý¾Ý¿â·þÎñÆ÷À´½²£¬¶àÒ»¸öÁ¬½Ó¾ÍÒª¶àÏûºÄÒ»·Ý×ÊÔ´£¬Èç¹û´óÁ¿Óû§Á¬½Ó½øÈëÊý¾Ý¿âϵͳµ«È´²»½øÐÐÈκεIJÙ×÷£¬ÕâÎÞÐÎÖ®ÖоͰװ×Ôì³ÉÁË·þÎñÆ÷ϵͳ×ÊÔ´µÄÀË·Ñ£¬Í¬Ê±Ôì³É·þÎñÆ÷¸ºÔصÄÌá¸ß£¬¶ÔÓÚÄÇЩȷʵÔÚ¹¤×÷µÄÓû§À´½²£¬¾Í²»ÄÜ×î´óÏ޶ȵÄÀûÓ÷þÎñÆ÷µÄ×ÊÔ´£¬ÑÏÖØÇé¿öÏ¿ÉÄÜÔì³ÉϵͳÐÔÄܵļ±¾çϽµ¡£
¡¡¡¡Õë¶ÔÕâÖÖÎÊÌ⣬¸ÃÈçºÎ´¦ÀíÄØ£¿¶ÔÓÚÄ¿Ç°Á÷ÐеÄÈý²ã½á¹¹£¨Browser/Application/Server£©¿ª·¢À´½²£¬Õâ¸öÎÊÌâ¿ÉÒÔͨ¹ýÉèÖÃÓ¦Ó÷þÎñÆ÷¶ËµÄÁ¬½Ó¹²Ïí³Ø£¨shared pool£©À´±ÜÃâ¡£µ«¶ÔÓÚ´«Í³µÄÁ½²ã½á¹¹£¨Client/Server£©Ó¦Ó㬾ͱØÐëÓÉÎÒÃÇÈËΪ¸ÉÔ¤À´±ÜÃâÕâÖÖ×ÊÔ´ÀË·ÑÇé¿ö¡£¾ßÌå¿ÉÒÔͨ¹ýÒ»¸öºǫ́ÈÎÎñÀ´¼à¿ØϵͳÖеÄËùÓнø³Ì£¬¶ÔÓÚÄÇЩ¿ÕÏг¬¹ýÒ»¶¨Ê±¼äµÄ½ø³Ì²ÉÈ¡Ò»¶¨µÄÌØÊâ´¦Àí´ëÊ©£¬ÈçÔÚ¿Í»§¶ËÌáʾÓû§Á¬½Óʱ¼äÌ«³¤£¬Èç¹ûûÓкóÐø²Ù×÷ϵͳ½«×Ô¶¯É±µô¸ÃÁ¬½Ó»òÕßÖ±½Ó½«¸Ã¿ÕÏÐÁ¬½Óɱµô¡£ÏÂÃæ¾ÍÀ´¾ßÌåÌÖÂÛÈçºÎÔÚOracle 8x»·¾³ÏÂʵÏÖÓû§½ø³ÌµÄ×Ô¶¯¼à¿Ø¼°Æä¶Ô¶Ô³¬¹ýÒ»¶¨¿ÕÏÐʱ¼äÁ¬½ÓµÄ´¦Àí°ì·¨¡£
¡¡¡¡Ò»¡¢Ê¶±ðϵͳÖг¬¹ýÒ»¶¨¿ÕÏÐʱ¼äµÄÁ¬½Ó
¡¡¡¡ÒªÊµÏÖºǫ́ÈÎÎñ×Ô¶¯¶Ô³¬¹ýÒ»¶¨Ê±¼ä¿ÕÏÐÁ¬½ÓµÄ´¦Àí£¬Ê×ÏȵÚÒ»²½¹¤×÷¾ÍÊÇÒª´ÓËùÓÐÓëÊý¾Ý¿â·þÎñÆ÷µÄÁ¬½ÓÖÐʶ±ð³öÄÇЩÁ¬½ÓÐèÒª´¦Àí£¬Ò²¾ÍÊÇÐèÒª»ñµÃÓë·þÎñÆ÷Á¬½ÓµÄÿ¸öÓû§µÄµÇ½ʱ¼ä¼°Æä×îºóÒ»´Î²Ù×÷ºóµÄ¿ÕÏÐʱ¼ä¡£ÔÚOracleϵͳÖУ¬ÓÐÒ»¸ö¶¯Ì¬ÐÔÄÜÊÓͼv$session£¬¸ÃÊÓͼ±£´æ×Åϵͳµ±Ç°Á¬½ÓµÄ¸÷ÖÖ¶¯Ì¬ÐÅÏ¢¡£ÆäÖУ¬ÓÐÁ½¸ö×Ö¶ÎLOGON_TIMEºÍ LAST_CALL_ET¿ÉÒԵõ½ÉÏÃæµÄÁ½¸ö´ð°¸¡£
¡¡¡¡l LOGON_TIMEÊÇÒ»¸öÈÕÆÚÐÍ£¨Date£©×ֶΣ¬ÎªÓû§µÇ½ʱ¼ä£»
¡¡¡¡l LAST_CALL_ETÊÇÒ»¸öÊý×ÖÐÍ£¨Number£©×ֶΣ¬Æ京ÒåÊÇÓû§×îºóÒ»ÌõÓï¾äÖ´ÐÐÍê±ÏºóµÄʱ¼ä£¬µ¥Î»ÎªÃ롣ÿ´ÎÓû§Ö´ÐÐÒ»¸öеÄÓï¾äºó£¬¸Ã×ֶθ´Î»Îª0£¬ÖØпªÊ¼¼ÇÊý¡£ÎÒÃÇ¿ÉÒÔͨ¹ý¸Ã×Ö¶ÎÀ´»ñµÃÒ»¸öÁ¬½ÓÓû§×îºóÒ»´Î²Ù×÷Êý¾Ý¿âºóµÄ¿ÕÏÐʱ¼ä¡£
¡¡¡¡ÏÂÃæµÄSQL²éѯÓï¾ä¿ÉÒԵõ½Ó뵱ǰÊý¾Ý¿âÁ¬½ÓµÄËùÓÐÓû§µÄһЩ»ù±¾Çé¿ö£¬ÈçÓû§Ãû¡¢×´Ì¬¡¢Á¬½Ó»úÆ÷µÄÃû³Æ£¬²Ù×÷ϵͳÖÐÓû§µÄÃû³Æ£¬UNIXϵͳµÄ½ø³ÌºÅ£¬ÔÚUNIX²Ù×÷ϵͳ¼¶¶Ï¿ªÁ¬½ÓµÄÓï¾ä£¬OracleÊý¾Ý¿âϵͳ¶Ï¿ªÁ¬½ÓµÄÓï¾ä£¬µÇ½ʱ¼äÒÔ¼°×îºóÒ»´Î²Ù×÷µ½ÏÖÔڵĿÕÏÐʱ¼äµÈµÈ¡£
SELECT s.username Óû§Ãû³Æ, s.status ״̬,s.machine »úÆ÷Ãû³Æ,
¡¡¡¡¡¡¡¡osuser ²Ù×÷ϵͳÓû§Ãû³Æ,spid UNIX½ø³ÌºÅ,
'kill -9 '||spid UNIX¼¶¶Ï¿ªÁ¬½Ó,
'alter system kill session ' ||''''||s.sid||','||s.serial# || ''';' Oracle¼¶¶Ï¿ªÁ¬½Ó,
TO_CHAR (logon_time, 'dd/mm/yyyy hh24:mi:ss') µÇ½ʱ¼ä,
last_call_et ¿ÕÏÐʱ¼äÃë,
TO_CHAR (TRUNC (last_call_et / 3600, 0))||' '||' HRS '||
TO_CHAR (
TRUNC ((last_call_et - TRUNC (last_call_et / 3600, 0) * 3600) / 60, 0)
) ||' MINS' ¿ÕÏÐʱ¼äСʱ·ÖÖÓ,
module Ä£¿é
FROM v$session s, v$process p
WHERE TYPE = 'USER'
AND p.addr = s.paddr
AND status != 'KILLED'
-- AND SUBSTR (machine, 1, 19) NOT IN ('»úÆ÷Ãû')
AND last_call_et > 60 * 60 * 1 -- ¿ÕÏÐʱ¼ä³¬¹ý1СʱµÄÁ¬½Ó
ORDER BY last_call_et desc;
¡¡¡¡ÔÚÉÏÃæµÄ²éѯÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýSUBSTR (machine, 1, 19) NOT IN ('»úÆ÷Ãû')Õâ¸öÌõ¼þÀ´ÆÁ±ÎһЩ»úÆ÷£¬ÕâЩ»úÆ÷¿ÉÄÜÐèÒªÔËÐÐһЩºÄ·ÑºÜ³¤Ê±¼äµÄSQLÓï¾ä»òÆäËûһЩÌØÊâÇé¿öµÄ»úÆ÷¡£ÆÁ±ÎÕâЩ»úÆ÷µÄÔÒò¾ÍÊÇÔÚºóÃæµÄºǫ́×Ô¶¯Ê¶±ð¼°´¦ÀíÈÎÎñÖжÔÕâЩ»úÆ÷²»×÷´¦Àí¡£
¶þ¡¢Ê¶±ð¼°¶Ï¿ª¿ÕÏÐÓû§µÄ´æ´¢¹ý³Ì
¡¡¡¡ÉÏÃæµÄ²éѯÓï¾ä¿ÉÒԵõ½ÏµÍ³ÖÐËùÓеÄÁ¬½ÓÓû§µÄһЩ»ù±¾Çé¿ö£¬µ«ÊÇÓÖÈçºÎÀ´ÊµÏÖϵͳ×Ô¶¯ÅжϿÕÏг¬¹ýÒ»¶¨Ê±¼äµÄÁ¬½Ó²¢½«Æä×Ô¶¯¶Ï¿ªÄØ£¿OracleϵͳÌṩÁËÒ»ÖÖ³Æ֮Ϊºǫ́ÈÎÎñ£¨Job£©×Ô¶¯´¦ÀíµÄ»úÖÆ¡£ÎÒÃÇ¿ÉÒÔ±àдһ¸öºǫ́ÈÎÎñÀ´¶¨Ê±Ö´ÐУ¬´Ó¶øÅжÏÊÇ·ñ´æÔÚÕâÑùµÄÓû§Á¬½Ó£¬Èç¹û´æÔÚ£¬Ôòͨ¹ýºǫ́ÈÎÎñ½«Æä×Ô¶¯¶Ï¿ª¡£
¡¡¡¡Ê×ÏÈ´´½¨Ò»¸ö´æ´¢¹ý³ÌÀ´Íê³É¿ÕÏÐÒ»¶¨Ê±¼äÓû§µÄʶ±ðºÍ¶Ï¿ª¹¤×÷£¬È»ºóÌí¼ÓÒ»¸öºǫ́ÈÎÎñÀ´¶¨Ê±£¨¸ù¾Ý¿ÕÏÐʱ¼ä³¤¶ÌÀ´È·¶¨£©Ö´Ðиùý³Ì£¬¼´¿ÉʵÏÖ×Ô¶¯¶Ï¿ªÏµÍ³ÖпÕÏг¬¹ýÒ»¶¨Ê±¼äÓû§µÄÐèÇó¡£
¡¡¡¡´æ´¢¹ý³Ìp_monitor¼ûÏ£¬ÆäÖвÎÊýan_nimutesΪÓû§ÊäÈë²ÎÊý£¬ÓÃÀ´È·¶¨Ê¶±ðºÍ¶Ï¿ª¶à³¤¿ÕÏÐʱ¼äÁ¬½ÓµÄÓû§£¬µ¥Î»Îª·ÖÖÓ£¬Ä¬ÈÏΪ60·ÖÖÓ£¬Ò²¾ÍÊÇ1Сʱ¡£ÐèҪעÒâÒ»µãµÄÊÇ£¬¸Ã´æ´¢¹ý³Ì£¬ÐèÒªÒÔsysÓû§Éí·ÝÔËÐС£ÏàÓ¦£¬µ÷Óøô洢¹ý³ÌµÄºǫ́ÈÎÎñÒ²ÐèÒªÒÔSYSÉí·ÝÀ´Ìí¼Ó¡£
CREATE OR REPLACE PROCEDURE P_MONITOR(
AN_MINUTES NUMBER DEFAULT 60)
/*******************************************
´æ´¢¹ý³ÌÓÃ;£ºÊ¶±ð³öϵͳÖг¬¹ýÒ»¶¨¿ÕÏÐÁ¬½Óʱ¼ä(
¡¡ AS_MINUTES)µÄÓû§£¬²¢½«Æäkillµô²ÎÊý:
¡¡ AN_MINUTES ¿ÕÏÐʱ¼äÊý£¬µ¥Î»Îª·ÖÖÓ£¬Ä¬ÈÏΪ60·ÖÖÓ
********************************************/
AS
¡¡v_Str VARCHAR2(100);
¡¡CURSOR C_users(v_minutes number) IS ¡¡SELECT s.username,
¡¡s.status, s.machine, 'alter system kill session '
¡¡||''''||s.sid||','||s.serial# ||'''' operates
¡¡FROM v$session s, v$process p
¡¡WHERE TYPE = 'USER'
¡¡AND p.addr = s.paddr
¡¡AND status != 'KILLED'
¡¡-- AND SUBSTR (machine, 1, 19) NOT IN ('ÐèÒªÆÁ±Î²»±»´¦ÀíµÄ»úÆ÷Ãû')
¡¡AND last_call_et > v_minutes*60
¡¡ORDER BY last_call_et desc;
BEGIN
FOR T_users IN C_users(an_minutes) LOOP
v_Str := T_USERS.OPERATES;
EXECUTE IMMEDIATE v_str;
END LOOP;
END;
/
¡¡¡¡Èý¡¢ºǫ́ÈÎÎñµÄ¶¨Ê±Ö´ÐÐ
¡¡¡¡×îºó£¬ÎÒÃÇΪϵͳÌí¼ÓÒ»¸ö¶¨Ê±ÈÎÎñ£¬¶¨Ê±µ÷ÓÃÉÏÃæ´´½¨µÄ´æ´¢¹ý³Ì£¬¼´¿ÉÍê³Éϵͳ×Ô¶¯Ê¶±ðºÍ´¦Àí¿ÕÏÐÓû§µÄ¹¤×÷¡£
¡¡¡¡ÏÂÃæÊÇÒ»¸öʵ¼Êµ÷ÓõÄÀý×Ó£¬ÔÚsysÓû§Ï£¬Ê×ÏÈÌí¼ÓÒ»¸öÈÎÎñ£¬¸ÃÈÎÎñÿ¸ô°ëСʱÔËÐÐÒ»´Î£¬Ã¿´Î¾ùµ÷ÓÃP_monitor´æ´¢¹ý³Ì£¬ÕÒ³öϵͳÖпÕÏÐʱ¼ä³¬¹ý1СʱµÄÁ¬½Ó£¬È»ºó×Ô¶¯¶Ï¿ª¡£
DECLARE
jobno number;
BEGIN
DBMS_JOB.SUBMIT(
job => jobno,
what => 'p_monitor(60);',
next_date => SYSDATE,
interval => '/*1:Hr*/ sysdate + 30/1440); -- ÿ°ëСʱÔËÐÐÒ»´Î
END;
/