Oracle殺死死鎖進程
先查看哪些表被鎖住了:
select bownerbobject_nameasession_idalocked_mode
from v$locked_object adba_objects b
where bobject_id = aobject_id;
OWNER OBJECT_NAME SESSION_ID LOCKED_MODE
WSSB SBDA_PSHPFTDT
WSSB_RTREPOS WB_RT_SERVICE_QUEUE_TAB
WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB
WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB
WSSB SBDA_PSDBDT
WSSB_RTREPOS WB_RT_AUDIT_DETAIL
select busernamebsidbserial#logon_time
from v$locked_object av$session b
where asession_id = bsid order by blogon_time;
USERNAME SID SERIAL# LOGON_TIME
WSSB_RTACCESS
WSSB_RTACCESS
殺進程中的會話:
alter system kill session ;sidserial#;;
eg
alter system kill session ;;;
如果有ora錯誤則在後面加immediate;alter system kill session ;; immediate
如何殺死oracle死鎖進程
1查哪個過程被鎖:
查V$DB_OBJECT_CACHE視圖:
SELECT * FROM V$DB_OBJECT_CACHE WHERE OWNER=;過程的所屬用戶; AND CLOCKS!=;;;
查是哪一個SID通過SID可知道是哪個SESSION:
查V$ACCESS視圖:
SELECT * FROM V$ACCESS WHERE OWNER=;過程的所屬用戶; AND NAME=;剛才查到的過程名;;
查出SID和SERIAL#
查V$SESSION視圖:
SELECT SIDSERIAL#PADDR FROM V$SESSION WHERE SID=;剛才查到的SID;;
查V$PROCESS視圖:
SELECT SPID FROM V$PROCESS WHERE ADDR=;剛才查到的PADDR;;
殺進程
()先殺ORACLE進程:
ALTER SYSTEM KILL SESSION ;查出的SID查出的SERIAL#;;
()再殺操作系統進程:
KILL 剛才查出的SPID或ORAKILL 剛才查出的SID 剛才查出的SPID
Oracle的死鎖
查詢數據庫死鎖
select tusername||; ;||tsid||;
;||tserial#||; ;||tlogon_time||;
;||tsql_text
from v$locked_object tv$session tv$sqltext t
where tsession_id=tsid
and tsql_address=taddress
order by tlogon_time;
查詢出來的結果就是有死鎖的session了下面就是殺掉拿到上面查詢出來的SID和SERIAL#填入到下面的語句中
alter system kill session ;sidserial#;;
一般情況可以解決數據庫存在的死鎖了或通過session id 查到對應的操作系統進程在Unix中殺掉操作系統的進程
SELECT ausernamecspid AS os_process_idcpid
AS oracle_process_id FROM v$session av$process c
WHERE caddr=apaddr and asid= and aserial#= ;
然後采用kill (unix) 或 orakill(windows )
在Unix中
ps ef|grep os_process_id
kill os_process_id
ps ef|grep os_process_id
經常在Oracle的使用過程中碰到這個問題所以也總結了一點解決方法
)查找死鎖的進程
sqlplus "/as sysdba" (sys/change_on_install)
SELECT susernamelOBJECT_IDlSESSION_IDsSERIAL#
lORACLE_USERNAMElOS_USER_NAMElPROCESS
FROM V$LOCKED_OBJECT lV$SESSION S WHERE lSESSION_ID=SSID;
)kill掉這個死鎖的進程
alter system kill session ‘sidserial#’; (其中sid=lsession_id)
)如果還不能解決
select prospid from v$session ses
v$process pro where sessid=XX and
sespaddr=proaddr;
其中sid用死鎖的sid替換:
exit
ps ef|grep spid
其中spid是這個進程的進程號kill掉這個Oracle進程
From:http://tw.wingwit.com/Article/program/SQL/201405/30850.html