在 Oracle中清除过多非活动的会话
概述
本文讨论如何在oracle中清理非活动的会话
解决方案
1、检查数据库中存在的非活动会话
-- Check inactive and active session count select status, count(1) from v$session group by status; --Check username,programname inactive count select username, program, count(1) from v$session where status='INACTIVE' group by username, program; --Find more details of inactive count select p.username "OSUSERNAME", p.terminal,p.program,s.username "DBUSERNAME",s.command,s.status,s.server,s.process,s.machine,s.port,s.terminal,s.program,s.sid,s.serial#,p.spid FROM v$session s,v$process pWHERE p.addr=s.paddr and s.status='INACTIVE'order by 1,4;
2、Inactive session是由于Dead Connection或IDLE Connection造成的
DEAD 连接由 SQLNET.ORA 文件处理,通过配置参数 SQLNET.EXPIRE_TIME=minutes 打开 SQLNET ORA 文件并设置参数。它是客户端文件,所以在客户端设置它。
SQLNET.EXPIRE_TIME=60 (1 hour)
IDLE 连接设置为 USER PROFILES,定义具有 IDLE_TIME 限制的配置文件,以便在达到时间限制后终止 INACTIVE SESSION。
-- Need to enable resource limit so it automatic terminate the session. alter system set resource_limit=true scope=both; --Check user which profile it uses SELECT USERNAME, USER_ID, PROFILE FROM DBA_USERS; --check profile setting for IDLE_TIME select profile, limit from DBA_PROFILES where resource_name = 'IDLE_TIME'; --Alter IDLE TIME to 30 minutes after it disconnect alter profile customers_profiles limit idle_time 30;
注意:idle_time 参数将在 n 分钟不活动后断开会话。
喜欢请赞赏一下啦^_^
微信赞赏

支付宝赞赏

【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤