Oracle session active 和 inactive 状态 说明(一)

2014-11-24 18:11:18 · 作者: · 浏览: 0

. Session 状态说明


可以通过v$session 视图的status列查看session 的状态。 关于该视图的使用,参考联机文档:


V$SESSION






有关状态的说明:


1active 处于此状态的会话,表示正在执行,处于活动状态。


官方文档说明:


Any session that is connected to the database and is waiting for an event that does not belong to the Idle wait class is considered as an active session.



2killed处于此状态的会话,被标注为删除,表示出现了错误,正在回滚。


当然,也是占用系统资源的。还有一点就是,killed的状态一般会持续较长时间,而且用windows下的工具pl/sql developerkill掉,是不管用的,要用命令:alter system kill session 'sid,serial#' ;



3inactive 处于此状态的会话表示不是正在执行的


该状态处于等待操作(即等待需要执行的SQL语句),通常当DML语句已经完成。 但连接没有释放,这个可能是程序中没有释放,如果是使用中间件来连接的话,也可能是中间件的配置或者是bug 导致。



inactive数据库本身没有什么影响,但是如果程序没有及时commit,那么就会造成占用过多会话。容易是DB session 达到极限值。


问了几个朋友,他们的做法是不处理inactive 状态的session 如果达到了session 的最大值, 就增加processes sessions 参数。 如果kill inactive session 可能会到中间件有影响。 具体中间件这块我也不太熟,等以后弄清楚了,在说。




. 处理inactive 状态的session


在前面说不处理inactive 状态的session,但是还是有方法来解决的。 有两种方法。



2.1 sqlnet.ora文件中设置expire_time 参数


官网有关这个参数的说明:


http://download.oracle.com/docs/cd/B19306_01/network.102/b14213/sqlnet.htm



SQLNET.EXPIRE_TIME


Purpose


Use parameter SQLNET.EXPIRE_TIME to specify a the time interval, in minutes, to send a probe to verify that client/server connections are active. Setting a value greater than 0 ensures that connections are not left open indefinitely, due to an abnormal client termination. If the probe finds a terminated connection, or a connection that is no longer in use, it returns an error, causing the server process to exit. This parameter is primarily intended for the database server, which typically handles multiple connections at any one time.


sqlnet.expire_time 的原理:Oracle Server 发送包探测dead connection ,如果连接关闭,或者不再用,则关闭相应的server process.



Limitations on using this terminated connection detection feature are:


1It is not allowed on bequeathed connections.


2Though very small, a probe packet generates additional traffic that may downgrade network performance.


3Depending on which operating system is in use, the server may need to perform additional processing to distinguish the connection probing event from other events that occur. This can also result in degraded network performance.



Default 0


Minimum Value 0


Recommended Value 10



Example


SQLNET.EXPIRE_TIME=10




2.2 设置用户profileidle_time 参数





注意,要启用idle_time 要先启用RESOURCE_LIMIT参数。 该参数默认是False 官网说明如下:



RESOURCE_LIMIT



RESOURCE_LIMIT determines whether resource limits are enforced in database profiles.



Values:


TRUE Enables the enforcement of resource limits


FALSEDisables the enforcement of resource limits




IDLE_TIME Specify the permitted periods of continuous inactive time during a session, expressed in minutes. Long-running queries and other operations are not subject to this limit.



A valid database connection that is idle will respond to the probe packet causing no action on the part of the Server , whereas the resource_limit will snipe the session when idle_time is exceeded. The 'sniped' session will get disconnected when the user(or the user process) tries to communicate with the server again.



-- 通过idle_time限制session idle 时间。session idle超过设置时间,状态为sniped (v$session).,然而OS下的process并不会释放,当session(user process) 再次与server process 通讯,将关闭相应的server process.



What d