查询用户open cursors的分布情况

2020-09-01 00:00:00 查询 生产 会话 游标 打开

生产库由于开发的各种原因导致游标没有释放达到参数设置的上限,此时会话无法打开新的游标,数据库告警日志也会有告警记录,此时需要我们查询那些用户的哪些游标打开了而没有关闭。

下面是常用的查询相关v$视图

1 查询打开的大游标数用户信息,已经达到参数open_cursors的大值
select a.value,s.username,s.sid,s.serial# from v$sesstat a,v$statname b,v$session s where a.statistic#=b.statistic# and
s.sid=a.sid and b.name='opened cursors current' and s.username is not null and a.value =(select value from v$parameter where name='open_cursors');
VALUE USERNAME SID SERIAL#
---------- ------------------------------ ---------- ----------
300 JAVAFRAME 2 61222
300 JAVAFRAME 100 28303
说明:用户JAVAFRAME的会话打开的游标达300上限值。


2 根据上述查询的sid查询某个会话的打开游标以及对应的SQL。
col user_name for a20;
set line 200 pages 100;
select sid,sql_text,sql_id,user_name,count(*) as "OPEN_CURSORS" from v$open_cursor where sid=&sid group by sid,sql_text,sql_id,user_name;


3 从登录机器和用户名以及SQL的纬度,统计打开的游标数
col machine for a20;
set line 200 pages 100;
select s.machine,oc.user_name,oc.sql_text,count(1) from v$open_cursor oc,v$session s where oc.sid=s.sid and user_name!='SYS' group by user_name,sql_text,machine having count(1) >100 order by count(1) desc;
MACHINE USER_NAME SQL_TEXT COUNT(1)
-------------------- -------------------- ------------------------------------------------------------ ----------
FH-YY-V069055 JAVAFRAME select rowid, f_sessionname,f_sessionvalue from JAVAFRAME.t_ 17730
aqscgl-app-v064 JAVAFRAME select rowid, f_sessionname,f_sessionvalue from JAVAFRAME.t_ 3795

查询目前大的cursor数以及允许的cursor数

col highest_open_cur for 99999;
col max_open_cur for a20;
set line 200 pages 100;
select max(a.value) as highest_open_cur,p.value as max_open_cur from v$sesstat a,v$statname b,v$parameter p where a.statistic#=b.statistic# and b.name='opened cursors current' and p.name='open_cursors' group by p.value;

HIGHEST_OPEN_CUR MAX_OPEN_CUR
---------------- --------------------
300 300



相关文章