Oracle HowTo:如何快速杀死占用过多资源(CPU,内存)的数据库进程

上一篇 / 下一篇  2009-01-12 22:56:34 / 个人分类:Oracle

  • 文件版本: V1.0
  • 开发商: 本站原创
  • 文件来源: 本地
  • 界面语言: 简体中文
  • 授权方式: 免费
  • 运行平台: Win9X/Win2000/WinXP
很多时候由于异常或程序错误会导致个别进程占用大量系统资源,需要结束这些进程,通常可以使用以下命令Kill进程:51Testing软件测试网 o'D(jL1|v
alter system kill session 'sid,serial#';

]2H;zX9p}1i0但是此命令释放资源极为缓慢,具体可以参考:Oracle中Kill session的研究.
C.ap T"@sP8_0为了更快速的释放资源,通常我们使用如下步骤来Kill进程:51Testing软件测试网C1ka w |/h0n}tSC
1.首先在操作系统级kill进程
UK(Z2R#\KZZ02.在数据库内部kill session51Testing软件测试网@7\W)h,D
这样通常可以快速中止进程,释放资源。51Testing软件测试网{D2K8? ]oA8E
51Testing软件测试网Rj,H U/f6K&E D6v*b
今天就遇到这样一个案例,其他朋友在数据库里kill session,可是长时间仍无效果:51Testing软件测试网i ^/lU3c r#] N
[oracle@danaly ~]$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 27 11:09:50 2005

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

SQL> select sid,username,status from v$session;

       SID USERNAME                       STATUS
---------- ------------------------------ --------
....
       154 SCOTT                          KILLED
...

30 rows selected.

J4Q8r gK \XH0那按照我前面提到的步骤,首先查询得到该session对应的OS进程号:51Testing软件测试网 XV5D'f4yR
SQL> select 'kill -9 '||spid from v$process where addr = (select paddr from v$session where sid=&sid);
Enter value for sid: 154
old   1: select 'kill -9 '||spid from v$process where addr = (select paddr from v$session where sid=&sid)
new   1: select 'kill -9 '||spid from v$process where addr = (select paddr from v$session where sid=154)

'KILL-9'||SPID
--------------------
kill -9 22702

SQL> !

-cF:D}$ICd{[0在操作系统级kill该进程:
.Ab6V`r0
[oracle@danaly ~]$ ps -ef|grep 22702
oracle   22702     1  0 Oct25 ?        00:00:02 oracledanaly (LOCAL=NO)
oracle   12082 12063  0 11:12 pts/1    00:00:00 grep 22702
[oracle@danaly ~]$ kill -9 22702
[oracle@danaly ~]$ ps -ef|grep 22702
oracle   12088 12063  0 11:12 pts/1    00:00:00 grep 22702
[oracle@danaly ~]$ exit
exit

SQL> select sid,username,status from v$session;

       SID USERNAME                       STATUS
---------- ------------------------------ --------
...
       154 SCOTT                          KILLED
...

30 rows selected.

SQL> select sid,serial#,username from v$session where sid=154;

       SID    SERIAL# USERNAME
---------- ---------- ------------------------------
       154      56090 SCOTT
51Testing软件测试网+L&PJ zU&E
再次在数据库中kill该session,并指定immediate选项:
3m}0c g9ta2Xr0
SQL> alter system kill session '154,56090' immediate;

System altered.

SQL> select sid,serial#,username from v$session where sid=154;

no rows selected
51Testing软件测试网G/u8N(o,^P
此时该进程被迅速清除。

TAG: Oracle

 

评分:0

我来说两句

Open Toolbar