inactive sessiono

本文详细解析了Oracle数据库中inactive session状态的含义及其对系统的影响。同时介绍了两种处理inactive session的方法:一是通过设置sqlnet.ora文件中的expire_time参数实现;二是通过用户profile的idle_time参数进行限制。

http://blog.youkuaiyun.com/aaaaaaaa2000/article/details/7392431
在这个里面看到885的进程阻塞了很多其他进程,但是885进程的状态竟然是inactive session的,那这个inactive session 到底是干啥的?这个状态什么含义?



http://blog.youkuaiyun.com/tianlesoftware/article/details/6539297--这个文件里有对inactive

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

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

以上两者组合使用,减少server process,防止process超过init$ORACLE_SID极限值。




有关状态的说明:

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 developer来kill掉,是不管用的,要用命令:alter system kill session 'sid,serial#' ;

 

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

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

 

            inactive对数据库本身没有什么影响,但是如果程序没有及时commit,那么就会造成占用过多会话。容易是DB 的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:

(1)It is not allowed on bequeathed connections.-----对 bequeathed connections说明

Simply an Oracle client-server connection that uses IPC (Inter Process Communication) and not TCP (network connection established via the Listener).
In other words, the client and server process communicates directly (via IPC) with one another. There's no network layer in between that serves as the communication layer.
Obviously, this also means that both client process and server process run on the same kernel - as IPC is a communication method that the kernel provides for processes it is executing, to communicate with one another.
(是否可以理解为client与server是在同一机器上)

(2)Though very small, a probe packet generates additional traffic that may downgrade network performance.---会占用网络带宽

(3)Depending 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----(分钟)
修改完之后需要reload监听

 

 

2.2 设置用户profileidle_time 参数

           

之前整理的一篇有关profile的文章:

            Oracle 用户 profile 属性

            http://blog.youkuaiyun.com/tianlesoftware/archive/2011/03/10/6238279.aspx

 

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

 

RESOURCE_LIMIT

Property

Description

Parameter type

Boolean

Default value

false

Modifiable

ALTER SYSTEM

Range of values

true | false

 

            RESOURCE_LIMIT determines whether resource limits are enforced in database profiles.

 

Values:

            TRUE: Enables the enforcement of resource limits

            FALSE:Disables the enforcement of resource limits

 

如下blog 在这块说的比较清楚,并提供了相关的脚本:

            sqlnet.expire_time and IDLE_TIME

            http://space.itpub.net/10687595/viewspace-420407

 

 

            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 exceededThe '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 does 'SNIPED' status in v$session mean?

            When IDLE_TIME is set in the users' profiles or the default profile. This will kill the sessions in the database (status in v$session now becomes SNIPED) and they will eventually disconnect. It does not always clean up the Unix session (LOCAL=NO sessions).

            At this time all oracle resources are released but the shadow processes remains and OS resources are not released. This shadow process is still counted towards the parameters of init.ora.

            This process is killed and entry from v$session is released only when user again tries to do something. Another way of forcing disconnect (if your users come in via SQL*Net) is to put the file sqlnet.ora on every client machine and include the parameter "SQLNET.EXPIRE_TIME" in it to force the close of the SQL*Net session

sqlnet.expire_time

            sqlnet.expire_time actually works on a different principle and is used to detect dead connections as opposed to disconnecting(actually 'sniping') a session based on idle_time which the profile accomplishes.


            But again, as you mentioned, expire_time works globally while idle_time profile works for that user. You can use both of them to make sure that the client not only gets sniped but also gets disconnected if the user process abnormally terminates.

 

修改示例:

SQL>alter profile default limit idle_time 10;

--需要重启下oracle







### Inactive状态的含义 在数据库管理中,`INACTIVE` 状态表示会话当前未执行任何SQL语句[^1]。这种状态下的会话可能仍然保持连接,但没有活跃的操作。通常,`INACTIVE` 状态的会话不会消耗大量资源,但如果数量过多,可能会导致系统资源紧张。 ### 解决与Inactive状态相关的问题 #### 1. **通过设置`expire_time`参数** 可以在`sqlnet.ora`文件中设置`expire_time`参数,以定期检查客户端是否仍然活动。如果客户端在指定时间内无响应,服务器将断开连接[^3]。 ```bash # sqlnet.ora 文件配置 SQLNET.EXPIRE_TIME=10 # 单位为分钟 ``` #### 2. **启用`RESOURCE_LIMIT`并设置`idle_time`** 需要先启用`RESOURCE_LIMIT`参数,然后通过修改用户配置文件(profile)来限制会话的空闲时间。当会话超过设定的空闲时间时,系统会自动断开连接。 ```sql -- 启用 RESOURCE_LIMIT 参数 ALTER SYSTEM SET RESOURCE_LIMIT=TRUE SCOPE=BOTH; -- 查看当前用户的 profile SELECT username, profile FROM dba_users WHERE username='YOUR_USERNAME'; -- 修改默认 profile 的 idle_time 参数 ALTER PROFILE DEFAULT LIMIT IDLE_TIME 10; -- 单位为分钟 -- 需要重启数据库使更改生效 ``` #### 3. **手动清理Inactive会话** 可以通过查询`v$session`视图找到所有`INACTIVE`状态的会话,并根据需要手动终止不必要的会话[^3]。 ```sql -- 查询 INACTIVE 状态的会话 SELECT sid, serial#, username, status FROM v$session WHERE status = 'INACTIVE' AND username IS NOT NULL; -- 终止特定会话 ALTER SYSTEM KILL SESSION 'sid,serial#'; ``` #### 4. **调整系统参数** 如果`INACTIVE`状态的会话数量接近系统限制,可以考虑增加`processes`和`sessions`参数的值[^2]。但这只是临时解决方案,应结合实际情况优化应用逻辑或中间件配置。 ```sql -- 查看当前参数值 SHOW PARAMETER processes; SHOW PARAMETER sessions; -- 修改参数值 ALTER SYSTEM SET processes=1000 SCOPE=SPFILE; ALTER SYSTEM SET sessions=1100 SCOPE=SPFILE; -- 需要重启数据库使更改生效 ``` ### 注意事项 - 在终止`INACTIVE`状态的会话前,需确认这些会话不会对中间件或其他应用程序产生影响[^2]。 - 如果问题与硬件(如RAID阵列)相关,则需检查阵列卡的状态并激活未激活的阵列[^4]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值