很多时候由于异常或程序错误会导致个别进程占用大量系统资源,需要结束这些进程,通常可以使用以下命令kill进程:
alter system kill session 'sid,serial#';
但是此命令释放资源极为缓慢,具体可以参考:oracle中kill session的研究.
为了更快速的释放资源,通常我们使用如下步骤来kill进程:
1.首先在操作系统级kill进程
2.在数据库内部kill session
这样通常可以快速中止进程,释放资源。
今天就遇到这样一个案例,其他朋友在数据库里kill session,可是长时间仍无效果:
[[email protected] ~]$ 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.
那按照我前面提到的步骤,首先查询得到该session对应的os进程号:
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> !
在操作系统级kill该进程:
[[email protected] ~]$ 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
[[email protected] ~]$ kill -9 22702
[[email protected] ~]$ ps -ef|grep 22702
oracle 12088 12063 0 11:12 pts/1 00:00:00 grep 22702
[[email protected] ~]$ 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
再次在数据库中kill该session,并指定immediate选项:
sql> alter system kill session '154,56090' immediate;
system altered.
sql> select sid,serial#,username from v$session where sid=154;
no rows selected
新闻热点
疑难解答