先查看哪些表被鎖住了:
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替換:
其中spid是這個進程的進程號,kill掉這個Oracle進程。