Oracle數據庫出現死鎖的時候可以按照以下處理步驟加以解決:
第一步:嘗試在sqlplus中通過sql命令進行刪除,如果能夠刪除成功,則萬事大吉!但通常情況下,出現死鎖時,想通過命令行或者通過Oracle的管理工具刪除有死鎖的session,oracle只會將該session標記為killed,但無法清除掉,往往需要通過第二步在操作系統層級進行刪除!
Connected to Oracle9i Enterprise Edition Release 9.2.0.1.0 Connected as quik SQL> select xidusn, object_id, session_id, locked_mode from v$locked_object; --查死鎖的對象,獲取其SESSION_ID XIDUSN OBJECT_ID SESSION_ID LOCKED_MODE ---------- ---------- ---------- ----------- 10 30724 29 3 10 30649 29 3 SQL> select username,sid,serial# from v$session where sid=29; --根據上步獲取到的sid查看其serial#號 USERNAME SID SERIAL# ------------------------------ ---------- ---------- QUIK 29 57107 SQL> alter system kill session '29,57107'; --刪除進程,如已經刪除過,則會報ora-00031的錯誤;否則oracle會將該session標記為killed狀態,等待一段時間看能否會自動消失,如長時間消失不掉,則需要做後續步驟 alter system kill session '29,57107' ORA-00031: session marked for kill SQL> select pro.spid from v$session ses,v$process pro where ses.sid=29 and ses.paddr=pro.addr; --查看spid號,以便在操作系統中根據該進程號刪除進程 SPID ------------ 2273286
第二步:進入操作系統進行刪除進程,本示例的操作系統是IBM aix。
Microsoft Windows XP [版本 5.1.2600] (C) 版權所有 1985-2001 Microsoft Corp. C:\Documents and Settings\Administrator>telnet 10.73.52.7 --通過telnet遠程登陸到數據庫服務器 AIX Version 5 (C) Copyrights by IBM and by others 1982, 2005.
login: root --錄入用戶名 root's Password: --錄入密碼 ******************************************************************************* * * * * * Welcome to AIX Version 5.3! * * * * * * Please see the README file in /usr/lpp/bos for information pertinent to * * this release of the AIX Operating System. * * * * * ******************************************************************************* Last unsuccessful login: Fri Apr 23 14:42:57 BEIDT 2010 on /dev/pts/1 from 10.73 .52.254 Last login: Fri Apr 23 15:27:50 BEIDT 2010 on /dev/pts/2 from 10.73.52.254 # ps -ef|grep 2273286 --查看進程詳情 root 2289864 2494636 0 17:07:15 pts/1 0:00 grep 2273286 oracle 2273286 1 0 14:38:24 - 0:21 oracleQUIK (LOCAL=NO) # kill -9 2273286 --刪除進程,小心操作,別寫錯進程號,如果oracle的關鍵進程被刪,數據庫會崩潰的! # ps -ef|grep 2273286 --再次查看 root 2289864 2494636 0 17:07:15 pts/1 0:00 grep 2273286 For Windows, at the DOS Prompt: orakill sid spid For UNIX at the command line> kill –9 spid