open_cursors和session_cached_cursors参数设置
open_cursors 指一个session最多打开的游标数。
用一下sql来确定这个值的大小
select max(count(*)) max_cacheable_cursors
from (select p.kglobt18 schema# -- parsing schema number
from sys.x$kglcursor p
where p.kglobt12 > 2 -- enough parse_calls
union all
select s.kglntsnm schema# -- authorized schema number
from sys.x$kglcursor c, sys.x$kglsn s
where c.kglobt12 > 2
and s.kglhdadr = c.kglhdadr)
group by schema#
session_cached_cursors是指session游标的缓存
session可以缓存多少个cursor,让后续相同的sql语句不再打开游标,来避免解析sql的过程来提高性能。
也就是划分一块内存区域,用来存储关闭了的cursor。当一个cursor关闭之后,oracle会检查这个cursor的request次数是否超过3次,如果超过了三次,就会放入session cursor cache,这样在下次parse的时候,就可以从session cursor cache中找到这个statement,然后调用,就省去了利用cpu资源来解释的过程。
使用下面的sql判断"session_cached_cursors" 的使用情况。如果使用率为100%则增大这个参数值。
select
"session_cached_cursors" parameter,
lpad(value, 5) value,
decode(value, 0, " n/a", to_char(100 * used / value, "990") || "%") usage
from
( select
max(s.value) used
from
v$statname n,
v$sesstat s
where
n.name = "session cursor cache count" and
s.statistic# = n.statistic#
),
( select
value
from
v$parameter
where
name = "session_cached_cursors"
)
union all
select
"open_cursors",
lpad(value, 5),
to_char(100 * used / value, "990") || "%"
from
( select
max(sum(s.value)) used
from
v$statname n,
v$sesstat s
where
n.name in ("opened cursors current", "session cursor cache count") and
s.statistic# = n.statistic#
group by
s.sid
),
( select
value
from
v$parameter
where
name = "open_cursors"
)
用一下语句可以看出hit cache的次数
SQL> select name,value as "hit" from v$sysstat where name="session cursor cache hits";
NAME
--------------------------------------------------------------------------------
hit
----------
session cursor cache hits
160608632
用以下语句可以看出所有的parse的次数
SQL> select name,value from v$sysstat where name="parse count (total)";
NAME
--------------------------------------------------------------------------------
VALUE
----------
parse count (total)
173250901
如果这两个值越接近,那就越好,因为每次parse的时候都是从cache 中hit的,所以就省去了cpu的parse的时间
如果前者的值比后者的值小的多,内存够大,就可以考虑增加session_cached_cursors的值了。
由于是初始化参数所以得加上scope=spfile修改如下
alter system set open_cursors=600 scope=both; #默认300
alter system set session_cached_cursors=40 scope=spfile; #默认20
注意:session_cached_cursors < open_cursors
SQL> show parameter cursors #查看语句
NAME TYPE
------------------------------------ ---------------------------------
VALUE
------------------------------
open_cursors integer
300
session_cached_cursors integer
20
###############################
本文属笔者原创
作者:john
转载请注明出处