Oracle之杀会话kill session的相关问题

0    323    2

Tags:

👉 本文共约7671个字,系统预计阅读时间或需29分钟。

前言部分

导读和注意事项

① killed状态的会话如何释放(如何找到后台进程)--重点?
② 授予普通用户可以kill自己用户session的权限
③ kill session和disconnect session的区别
④ v$session.CREATOR_ADDR列的使用
⑤ 对inactive会话的处理(1、sqlnet.ora文件中设置expire_time 参数 2、用户profile的idle_time 参数 3、找到很久没有响应的会话然后kill掉)
⑥ v$session.LAST_CALL_ET的使用
⑦ PMON的清理周期隐含参数"_PKT_PMON_INTERVAL"介绍

本文简介

今天同事杀会话的时候采用了alter system kill session ‘xxx,xxx’的方式,结果杀完后,v$session中还可以查到,就求助我,因为我之前杀会话都是带的immediate的,杀完后会立刻释放,v$session中也查询不到,同事现在的情况就只能杀后台进程了,但paddr列关联不到后台进程,查了下MOS还是给出了一些办法,整理了一下,分享给大家。

相关知识点扫盲

得到当前会话的几个SQL

Session 状态说明

Oracle 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 参数。 对于Inactive 状态的session,可以设置过期时间:
(1)sqlnet.ora文件中设置expire_time 参数
(2)设置用户profile的idle_time 参数
(3)找到很久没有响应的会话然后kill掉
当设置了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极限值。
本文会对这3种方式分别说明的。

清理inactive会话的3种方式

设置sqlnet.expire_time

可以在sqlnet.ora文件里面加上sqlnet.expire_time这个参数来解决,设置一个分钟数,这是ORACLE建议的DCD解决方法。
在 sqlnet.ora文件中设置expire_time 参数
官网有关这个参数的说明:
http://download.oracle.com/docs/cd/B19306_01/network.102/b14213/sqlnet.htm
Oracle® Database Net Services Reference 11g Release 2 (11.2)E10835-10
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

设置用户profile的idle_time 参数
Oracle 用户 profile 属性
http://blog.csdn.net/tianlesoftware/archive/2011/03/10/6238279.aspx
注意,要启用idle_time 要先启用RESOURCE_LIMIT参数。 该参数默认是False。 官网说明如下:
RESOURCE_LIMIT
PropertyDescription
Parameter typeBoolean
Default valuefalse
ModifiableALTER SYSTEM
Range of valuestrue | 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

找到很久没有响应的会话然后kill掉

关于v$session中LAST_CALL_ET列的理解:http://blog.itpub.net/26736162/viewspace-1762403/
根据v$session中LAST_CALL_ET列的意义我们可以写出如下的SQL脚本,没一个小时清理10个小时没有响应的会话:

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!
Oracle之杀会话kill session的相关问题后续精彩内容已被小麦苗无情隐藏,请输入验证码解锁本站所有文章!
验证码:
请先关注本站微信公众号,然后回复“验证码”,获取验证码。在微信里搜索“DB宝”或者“www_xmmup_com”或者微信扫描右侧二维码都可以关注本站微信公众号。

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复

嘿,我是小麦,需要帮助随时找我哦。
  • 18509239930
  • 个人微信

  • DB宝
  • 个人邮箱
  • 点击加入QQ群
  • 个人微店

  • 回到顶部