文章詳情頁
從問題入手幫你解決Oracle殺死死鎖進程
瀏覽:146日期:2023-11-25 15:20:44
Oracle殺死死鎖進程 先查看哪些表被鎖住了: select b.owner,b.object_name,a.session_id,a.locked_modefrom v$locked_object a,dba_objects bwhere b.object_id = a.object_id;OWNER OBJECT_NAME SESSION_ID LOCKED_MODE------------------------------ -----------------WSSB SBDA_PSHPFTDT 22 3WSSB_RTREPOS WB_RT_SERVICE_QUEUE_TAB 24 2WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB 29 2WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB 39 2WSSB SBDA_PSDBDT 47 3WSSB_RTREPOS WB_RT_AUDIT_DETAIL 47 3select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session bwhere a.session_id = b.sid order by b.logon_time;USERNAME SID SERIAL# LOGON_TIME------------------------------ ---------- -------WSSB_RTAccess 39 1178 2006-5-22 1WSSB_RTACCESS 29 5497 2006-5-22 1殺進程中的會話: alter system kill session 'sid,serial#';e.galter system kill session '29,5497';假如有ora-00031錯誤,則在后面加immediate;alter system kill session '29,5497' immediate; 如何殺死oracle死鎖進程 1.查哪個過程被鎖: 查V$DB_OBJECT_CACHE視圖: SELECT * FROM V$DB_OBJECT_CACHE WHERE OWNER='過程的所屬用戶' AND CLOCKS!='0'; 2. 查是哪一個SID,通過SID可知道是哪個SESSION: 查V$ACCESS視圖: SELECT * FROM V$ACCESS WHERE OWNER='過程的所屬用戶' AND NAME='剛才查到的過程名'; 3. 查出SID和SERIAL#: 查V$SESSION視圖: SELECT SID,SERIAL#,PADDR FROM V$SESSION WHERE SID='剛才查到的SID'; 查V$PROCESS視圖: SELECT SPID FROM V$PROCESS WHERE ADDR='剛才查到的PADDR'; 4. 殺進程: (1)先殺ORACLE進程: ALTER SYSTEM KILL SESSION '查出的SID,查出的SERIAL#'; (2)再殺操作系統進程: KILL -9 剛才查出的SPID或ORAKILL 剛才查出的SID 剛才查出的SPID。 Oracle的死鎖 查詢數據庫死鎖: select t2.username' 't2.sid' 't2.serial#' 't2.logon_time' 't3.sql_textfrom v$locked_object t1,v$session t2,v$sqltext t3where t1.session_id=t2.sid and t2.sql_address=t3.addressorder by t2.logon_time;查詢出來的結果就是有死鎖的session了,下面就是殺掉,拿到上面查詢出來的SID和SERIAL#,填入到下面的語句中: alter system kill session 'sid,serial#'; 一般情況可以解決數據庫存在的死鎖了,或通過session id 查到對應的操作系統進程,在Unix中殺掉操作系統的進程。 SELECT a.username,c.spid AS os_process_id,c.pid AS oracle_process_id FROM v$session a,v$process c WHERE c.addr=a.paddr and a.sid= and a.serial#= ;然后采用kill (unix) 或 orakill(windows )。 在Unix中: ps -efgrep os_process_idkill -9 os_process_idps -efgrep os_process_id經常在Oracle的使用過程中碰到這個問題,所以也總結了一點解決方法。 1)查找死鎖的進程: sqlplus '/as sysdba' (sys/change_on_install)SELECT s.username,l.OBJECT_ID,l.SESSION_ID,s.SERIAL#,l.ORACLE_USERNAME,l.OS_USER_NAME,l.PROCESS FROM V$LOCKED_OBJECT l,V$SESSION S WHERE l.SESSION_ID=S.SID;2)kill掉這個死鎖的進程: alter system kill session ‘sid,serial#’; (其中sid=l.session_id) 3)假如還不能解決: select pro.spid from v$session ses,v$process pro where ses.sid=XX and ses.paddr=pro.addr;其中sid用死鎖的sid替換: exitps -efgrep spid其中spid是這個進程的進程號,kill掉這個Oracle進程。
排行榜
