Oracle session active 和 inactive 状态 说明

原创 2011年06月12日 13:08:00
 

一. Session 状态说明

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

V$SESSION

http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/dynviews_3016.htm#REFRN30223

STATUS

VARCHAR2(8)

Status of the session:

ACTIVE - Session currently executing SQL

INACTIVE

KILLED - Session marked to be killed

CACHED - Session temporarily cached for use by Oracle*XA

SNIPED - Session inactive, waiting on the client

有关状态的说明:

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

官方文档说明:

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.

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

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

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

该状态处于等待操作(即等待需要执行的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:

(1)It is not allowed on bequeathed connections.

(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

2.2 设置用户profile的idle_time 参数

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

Oracle 用户 profile 属性

http://blog.csdn.net/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 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 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

查询应用的连接数SQL:

/* Formatted on 2011/6/12 13:06:23 (QP5 v5.163.1008.3004) */

SELECT b.MACHINE, b.PROGRAM, COUNT (*)

FROM v$process a, v$session b

WHERE a.ADDR = b.PADDR AND b.USERNAME IS NOT NULL

GROUP BY b.MACHINE, b.PROGRAM

ORDER BY COUNT (*) DESC;

Oracle session active 和 inactive 状态 说明的更多相关文章

  1. Oracle session连接数和inactive的问题记录

    Oracle session连接数和inactive的问题记录 http://timnity.javaeye.com/blog/280383 从上周起,服务器Oracle数据库出现问题,用不到半天,就 ...

  2. Oracle session inactive状态临时表数据未清空问题

    问题描述:Oracle数据库,java代码使用某数据库实例,获取connection并在使用结束关闭,而session未销毁,而是状态变为inactive从而导致临时表数据未清空. Oracle临时表 ...

  3. ORACLE中STATUS为INACTIVE但是SERVER为SHARED状态的会话浅析

    我们知道当ORACLE数据库启用共享服务器模式时,通过共享服务器模式连接到数据库的会话是有一些特征的.在v$session里面,其SERVER的状态一般为SHARED和NONE, 为SHARED时,表 ...

  4. Oracle查询session连接数和inactive以及 概要文件IDLE_TIME限制用户最大空闲连接时间

    -----############oracle会话和进程################----------------查询会话总数select count(*) from v$session;--查 ...

  5. oracle session 相关优化

    导读: 同学们是不是都用遇到过这种情况,一个业务系统开发期业务并发量只是估算一个值,而系统上线后这个并发量可能会出现溢出或是不够的   情况.在这种情况下我们DBA怎么给出合理的性能优化建议呢?本文就 ...

  6. [转]GameObject的Active与InActive

    GameObject的Active与InActive 1.Script可以控制InActive的GameObject,但前提是Script所依附的GameObject不能是InActive,一旦为In ...

  7. [Hibernate 2]session的三种状态

    一.Session的特点和获取 特点: Session不是线程安全的,它代表与数据库之间的一次操作,它的概念介于Connection和Transaction之间.  Session也称为持久化管理器, ...

  8. Asp.Net使用加密cookie代替session验证用户登录状态 源码分享

    首先 session 和 cache 拥有各自的优势而存在.  他们的优劣就不在这里讨论了. 本实例仅存储用户id于用户名,对于多级权限的架构,可以自行修改增加权限字段   本实例采用vs2010编写 ...

  9. Oracle数据库使用出现错误-状态: 失败 ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist

    Oracle数据库使用出现错误-状态: 失败 ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist ...

随机推荐

  1. PHP获取ip与ip所在城市

    1获取真实ip,本地测试总是::1 或者127.0.0.1 或者局域网的ip /** * 获取用户真实 IP */ function getIP() { static $realip; if (iss ...

  2. javascript方法--call()

    关于call方法,以前经常看到这个方法,但是也没怎么用心去学习,后来觉得不行,所以知识在一点一点补~ 今天对自己学习call方法做一下总结 其实,学了call方法,会发现call跟apply其实是很像 ...

  3. 简单理解Hash算法的作用

    什么是Hash Hash算法,简称散列算法,也成哈希算法(英译),是将一个大文件映射成一个小串字符.与指纹一样,就是以较短的信息来保证文件的唯一性的标志,这种标志与文件的每一个字节都相关,而且难以找到 ...

  4. 共享变量 static

    一个类,有static变量counter,所有类实例共享 如果多个类实例,通过多线程访问static变量,就会产生覆盖的情况. 会发现counter偏小. 解决方法: AtomicLong count ...

  5. jenkins上展示html报告【转载】

    转至博客:上海-悠悠 前言 在jenkins上展示html的报告,需要添加一个HTML Publisher plugin插件,把生成的html报告放到指定文件夹,这样就能用jenkins去读出指定文件 ...

  6. Science14年的聚类论文——Clustering by fast search and find of density peaks

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 这是一个比较新的聚类方法(文章中没看见作者对其取名,在这里我姑且称该方法为local density clu ...

  7. QT中ui更改后不能更新的解决方法

    ui源文件到界面显示的原理可以网上搜索,这里不再描述.简单讲就是先要从*.ui生成ui_*.h然后再编译,所以界面未更新实际上是因为ui_*.h这个文件没有更新导致的. 出现此问题后我尝试了以下几个方 ...

  8. QQ分享 QQ空间分享 API链接:

    QZone: "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={{URL}}&title={{TITL ...

  9. css - 字体图标的制作

    很多的时候我们在开发过程中一般都是直接使用图片,尤其在移动页面频繁请求图片对性能不是很好 ,所以图标字体的应用也越来越广泛.一般情况下直接用的是font awesome字体,但是有时候需要制作自己风格 ...

  10. canvas时钟效果

    话不多说,直接上代码 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/x ...