尝试在sqlplus中通过sql命令进行删除,如果能够删除成功,则万事大吉!但通常情况下,出现死锁时,想通过命令行或者通过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