[zt] 理解V$OPEN_CURSOR, V$SESSION_CACHED_CURSOR

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' order by value desc;   

 

--------------------------

 

 

理解V$OPEN_CURSOR, V$SESSION_CACHED_CURSOR
===========================================================
这两个概念很容易混淆。
概念:
OPEN_CURSOR,定义每个Session最大能够打开的游标数量。在init.ora文件中定义,可以通过select * from v$parameter where name = 'open_cursors'查询。
V$OPEN_CURSOR,当前Session缓存的游标,而不是曾经打开的游标。 V$SESSION_CACHED_CURSOR,当前Session已经关闭并被缓存的游标。
V$OPEN_CURSOR中显示的当前Session游标缓存中游标,如果要精确查询当前Session打开的游标总数,需要从V$ SESSTAT中查询。

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';

Session Cache的原理:
当设定SESSION_CACHED_CURSOR的值之后,当有parse请求的时候,Oracle会从library cache中查询。如果有超过3次同样的parse请求,这个游标将会存入Session的游标缓存中。对于将来同样的查询,就甚至不要soft parse,直接从Session的游标缓存中取。

验证:
登录两个SQL*PLUS客户端,分别为Session test和Session monitor。

1. 检查是否参数设置,以及执行的SQL语句是否在V$OPEN_CURSOR找到。
Session Test:
SQL> show parameter session_cached_cursors;

NAME TYPE VALUE
------------------------------
session_cached_cursors integer 0
SQL> select sid from v$mystat where rownum=1;
SID
----------
9
SQL> select sid from v$mystat where rownum=1;
SID
----------
9

通过如上的执行结果可以知道,当前参数设置session_cached_cursors的值为0,不缓存当前Session关闭的游标。当前Session的ID为9。

Session Monitor: SQL> SELECT SID, n.NAME para_name, s.VALUE used
2 FROM SYS.v_$statname n, SYS.v_$sesstat s
3 WHERE n.NAME IN ('opened cursors current', 'session cursor cache count')
4 AND s.statistic# = n.statistic# 5 AND SID = 9;
SID PARA_NAME USED
--- ------------------------------ ----------
9 opened cursors current 1
9 session cursor cache count 0
SQL> select SID, USER_NAME,SQL_TEXT from v$open_cursor where sid=9;
SID USER_NAME SQL_TEXT
--- ---------- -----------------------------------------------------------
9 SCOTT select sid from v$mystat where rownum=1

通过如上的执行结果可以知道,当前在V$OPEN_CURSOR存储一个游标,对应SQL为Session Test执行的最后一条语句。V$SESSION_CACHED_CURSOR没有存储游标。

2. 更改参数V$SESSION_CACHED_CURSOR值。

Session Test:
SQL> alter session set session_cached_cursors = 1;
Session altered.
SQL> show parameter session_cached_cursors;
NAME TYPE VALUE
------------------------------------ ----------- -------------------------
session_cached_cursors integer 1

3. 验证如下结论。如果游标被存入SESSION_CACHED_CURSOR,前提是游标已经关闭,游标对应的SQL被执行3次以上。OPEN_CURSOR中会存储保存在SESSION_CACHED_CURSOR以及打开的游标(不是精确值)。

Session Test:
SQL> select sid from v$mystat where rownum =1;
SID
----------
9
SQL> select sid from v$mystat where rownum =1;
SID
----------
9
SQL> select sid from v$mystat where rownum =1;
SID
----------
9

Session Monitor:
SQL> select SID, USER_NAME,SQL_TEXT from v$open_cursor where sid=9;
SID USER_NAME SQL_TEXT
--- ---------- -----------------------------------------------------------
9 SCOTT select sid from v$mystat where rownum =1
SQL> SELECT SID, n.NAME para_name, s.VALUE used
2 FROM SYS.v_$statname n, SYS.v_$sesstat s
3 WHERE n.NAME IN ('opened cursors current', 'session cursor cache count')
4 AND s.statistic# = n.statistic#
5 AND SID = 9;
SID PARA_NAME USED
--- ------------------------------ ----------
9 opened cursors current 1
9 session cursor cache count 0

v$open_cursor dooes not show all open cursors. it shows more than that, the best option to find the number of open cursors is from v$sysstat. 通过如上的执行结果可以知道,即使同一个游标被打开3次,在SESSION_CACHED_CURSOR的数量仍然为0。

下面,将会在Session Test中关闭游标(通过执行一条其他的语句)。

Session Test: SQL> select * from t where rownum!=7;
no rows selected

Session Monitor:
SQL> SELECT SID, n.NAME para_name, s.VALUE used
2 FROM SYS.v_$statname n, SYS.v_$sesstat s
3 WHERE n.NAME IN ('opened cursors current', 'session cursor cache count')
4 AND s.statistic# = n.statistic#
5 AND SID = 9;
SID PARA_NAME USED
--- ------------------------------ ----------
9 opened cursors current 1
9 session cursor cache count 1
SQL> select SID, USER_NAME,SQL_TEXT from v$open_cursor where sid=9;
SID USER_NAME SQL_TEXT
--- ---------- -----------------------------------------------------------
9 SCOTT select sid from v$mystat where rownum=1
9 SCOTT select * from t where rownum!=7

通过如上的执行结果可以知道,游标被打开3次之后,如果这个游标关闭之后,游标会被存储到SESSION_CACHED_CURSOR当中。同时,通过OPEN_CURSOR中显示的SQL可以得知,OPEN_CURSOR中会存储保存在SESSION_CACHED_CURSOR以及打开的游标(不是精确值)。

其他:SESSION_CACHED_CURSOR采用的是LRU算法,如果如果有新的游标需要缓存,而当前游标缓存已经满,最少使用的游标将会被清除出去。调整SESSION_CACHED_CURSOR参数。通过如下SQL得到从缓存中取游标以及取PARSE的数量,为调整作参考。

select cach.value cache_hits, prs.value all_parses,
prs.value-cach.value sess_cur_cache_not_used
from v$sesstat cach, v$sesstat prs,
v$statname nm1, v$statname nm2
where cach.statistic# = nm1.statistic# and
nm1.name = 'session cursor cache hits' and
prs.statistic#=nm2.statistic# and
nm2.name= 'parse count (total)' and
cach.sid= &sid and prs.sid= cach.sid ;

参考:
1. Monitoring Open and Cached Cursors
2. session_cached_cursor  

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/35489/viewspace-628445/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/35489/viewspace-628445/

定位到这里报错 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi
最新发布
12-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值