oracle给用户赋予kill会话,Oracle 使用Resource Manager自动KILL非活动会话

DBA经常会遇到因为应用没有断开会话导致数据库中的非活动会话太多内存被占满的情况,需要手工KILL或者定期使用脚本KILL会话来释放内存,甚至还有定期重启。

现在介绍一种使用Oracle资源管理器Resource Manager来完成的这一项工作的方式。资源管理器通过限制max_idle_time来达到此效果。

任何空闲时间超过300秒的会话都将被自动终止:

begin

dbms_resource_manager.create_pending_area;

dbms_resource_manager.create_plan(

plan => 'idle_mgmt_plan',

comment => 'Detects and kills idle sessions');

dbms_resource_manager.create_plan_directive(

plan => 'idle_mgmt_plan',

group_or_subplan => 'other_groups',

max_idle_time => 300,

comment => 'Limits idle time for all sessions to 300 seconds');

dbms_resource_manager.submit_pending_area;

end;

/

alter system set resource_manager_plan = idle_mgmt_plan;

也可以根据不同的需求,创建不同max_idle_time的组group_or_subplan。

还可以使用指令MAX_IDLE_BLOCKER_TIME,配置仅在会话阻止另一个会话时强制执行的会话的最大空闲时间。

监控

查看当前的资源管理计划

select name from v$rsrc_plan;

查看每个计划组的限制时长

select d.group_or_subplan, d.max_idle_time, d.max_idle_blocker_time from dba_rsrc_plan_directives d, v$rsrc_plan p where d.plan = p.name and (d.max_idle_time is not null or d.max_idle_blocker_time is not null) and d.status is null;

此查询显示到目前为止已被杀死的空闲会话数。

select name, idle_sessions_killed, idle_blkr_sessions_killed from v$rsrc_consumer_group;

官方建议最好在11g及以上版本使用此功能,否则有可能遇到BUG。

参考:

Using Resource Manager to Detect and Kill Idle Sessions (Doc ID 1557657.1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值