Oracle殺死死鎖進程
先查看哪些表被鎖住了:
select b.owner,b.object_name,a.session_id,a.locked_mode
from v$locked_object a,dba_objects b
where b.object_id = a.object_id;
OWNER OBJECT_NAME SESSION_ID LOCKED_MODE
------------------------------ -----------------
WSSB SBDA_PSHPFTDT 22 3
WSSB_RTREPOS WB_RT_SERVICE_QUEUE_TAB 24 2
WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB 29 2
WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB 39 2
WSSB SBDA_PSDBDT 47 3
WSSB_RTREPOS WB_RT_AUDIT_DETAIL 47 3
select b.username,b.sid,b.serial#,Logon_time
from v$locked_object a,v$session b
where a.session_id = b.sid order by b.Logon_time;
USERNAME SID SERIAL# LogoN_TIME
------------------------------ ---------- -------
WSSB_RTACCESS 39 1178 2006-5-22 1
WSSB_RTACCESS 29 5497 2006-5-22 1
殺進程中的會話:
alter system kill session 'sid,serial#';
e.g
alter 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_text
from v$locked_object t1,v$session t2,v$sqltext t3
where t1.session_id=t2.sid
and t2.sql_address=t3.address
order 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 -ef|grep os_process_id
kill -9 os_process_id
ps -ef|grep 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替換:
exit
ps -ef|grep spid
其中spid是這個進程的進程號,kill掉這個Oracle進程。