[20160201]db_link与子光标问题.txt

[20160201]db_link与子光标问题.txt

--生产系统遇到一个关于db_link产生大量子光标问题,当cursor_sharing=force的情况下,通过测试说明。
--注:这个问题我的测试仅仅存在10.2.0.4,11.2.0.4没有这个问题。

1.环境:
SCOTT@test> @&r/ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- ----------------------------------------------------------------
x86_64/Linux 2.4.xx            10.2.0.4.0     Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

SCOTT@test> CREATE PUBLIC DATABASE LINK loopback USING '192.168.100.33:1521/test';
Database link created.

create or replace view v_emp as select * from emp@loopback;
create or replace view vv_emp as select * from v_emp;
create or replace view vvv_emp as select * from emp@loopback;

2.测试:
SCOTT@test> alter system flush shared_pool;
System altered.

SCOTT@test> alter session set cursor_sharing=force ;
Session altered.

--执行如下语句:
select * from emp@loopback where empno=1;
select * from emp@loopback where empno=2;
select * from emp@loopback where empno=3;

SCOTT@test> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------
SQL_ID  4zzhmns2wsf4g, child number 2
select * from emp@loopback where empno=:"SYS_B_0"
NOTE: cannot fetch plan for SQL_ID: 4zzhmns2wsf4g, CHILD_NUMBER: 2
      Please verify value of SQL_ID and CHILD_NUMBER;
      It could also be that the plan is no longer in cursor cache (check v$sql_plan)
8 rows selected.

SCOTT@test> select count(*) from v$sql where sql_id='4zzhmns2wsf4g';
  COUNT(*)
----------
         3

--当sql语句仅仅含有远程表,无法通过dbms_xplan.display_cursor获得执行计划。
--可以发现产生了3个子光标。当大量相似的sql语句执行时(在cursor_sharing=force的情况下)会产生大量的子光标。

--换成如下语句依旧:
select * from v_emp where empno=1;
select * from v_emp where empno=2;
select * from v_emp where empno=3;

SCOTT@test> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
SQL_ID  ftmcqat5qjmzc, child number 2

select * from v_emp where empno=:"SYS_B_0"

NOTE: cannot fetch plan for SQL_ID: ftmcqat5qjmzc, CHILD_NUMBER: 2
      Please verify value of SQL_ID and CHILD_NUMBER;
      It could also be that the plan is no longer in cursor cache (check v$sql_plan)

SCOTT@test> select count(*) from v$sql where sql_id='ftmcqat5qjmzc';
  COUNT(*)
----------
         3

3.如果改用绑定变量看看:

variable x number ;
exec :x :=1;
select * from v_emp where empno=:x;
exec :x :=2;
select * from v_emp where empno=:x;
exec :x :=3;
select * from v_emp where empno=:x;

SCOTT@test> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------
SQL_ID  97pta6n0k7wtv, child number 0

select * from v_emp where empno=:x

NOTE: cannot fetch plan for SQL_ID: 97pta6n0k7wtv, CHILD_NUMBER: 0
      Please verify value of SQL_ID and CHILD_NUMBER;
      It could also be that the plan is no longer in cursor cache (check v$sql_plan)

SCOTT@test> select sql_text from v$sql where sql_id='97pta6n0k7wtv';
SQL_TEXT
------------------------------------------------------------
select * from v_emp where empno=:x

--可以发现仅仅1个子光标。

4.如果在访问时加入本地表看看:

select a.* from (select * from v_emp where empno=1) a,dual;
select a.* from (select * from v_emp where empno=2) a,dual;
select a.* from (select * from v_emp where empno=3) a,dual;

SCOTT@test> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  5puh2hnr82su0, child number 0
-------------------------------------
select a.* from (select * from v_emp where empno=:"SYS_B_0") a,dual
Plan hash value: 242706220
---------------------------------------------------------------------------------------
| Id  | Operation     | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | Inst   |IN-OUT|
---------------------------------------------------------------------------------------
|   1 |  NESTED LOOPS |      |      1 |    37 |     3   (0)| 00:00:01 |        |      |
|   2 |   FAST DUAL   |      |      1 |       |     2   (0)| 00:00:01 |        |      |
|   3 |   REMOTE      | EMP  |      1 |    37 |     1   (0)| 00:00:01 | LOOPB~ | R->S |
---------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$5C160134
   2 - SEL$5C160134 / DUAL@SEL$1
   3 - SEL$5C160134 / EMP@SEL$3

--可以发现child number 0,也没有产生子光标。

--在生产系统由于产生大量子光标,导致出现cursor: pin S wait on X等待事件,最终导致出现ora-4031 错误,目前不得不重启数据库。

Errors in file /u01/app/oracle/admin/mid/bdump/mid_smon_3832.trc:
ORA-04031: Message 4031 not found; No message file for product=RDBMS, facility=ORA; arguments: [4064] [shared pool] [lock table sys.mon_mods$ in ...] [sga heap(1,0)] [kglsim heap]
ORA-04031: Message 4031 not found; No message file for product=RDBMS, facility=ORA; arguments: [3896] [shared pool] [select ts#,file#,block#,cols...] [sga heap(1,0)] [kglsim object batch]

时间: 2024-10-23 08:52:40

[20160201]db_link与子光标问题.txt的相关文章

[20120421] cursor_sharing=similar和子光标问题.txt

[20120421] cursor_sharing=similar和子光标问题.txt 如果设置cursor_sharing=similar如果存在直方图会产生大量子光标,11GR2的新特性ACS可以很好的解决问题.自己做一些测试说明cursor_sharing=similar产生大量子光标的问题. SQL> select * from v$version; BANNER --------------------------------------------------------------

[20130104]oracle能有多少子光标.txt

[20121019]oracle能有多少子光标.txt 原链接:http://www.antognini.ch/2012/10/how-many-children-can-a-parent-cursor-have-1000000/ 看看oracle可能有多少子光标,也就是最大是多少?重复原作者的测试看看. 我的测试环境: SQL> select * from v$version where rownum BANNER ---------------------------------------

[20150812]11g子游标obsolete.txt

[20150812]11g子游标obsolete.txt --昨天听别人提到11.2.0.3下有一个bug,当子游标数量达到100后,如果产生101个子游标,那么父游标以及100个子游标会设置为obsoleted. --重新生成新的父游标.但是那些过期的child cursor不会从v$sql中消失,dbms_shared_pool.purge也无法将这些过期的child cursor --flush出去. --正好,我目前的测试环境主要是11.2.0.3,自己测试看看. 1.建立测试环境: S

[20171102]测试大量子光标对性能影响2.txt

[20171102]测试大量子光标对性能影响2.txt --//跟开发讲关于绑定变量的问题,总有人讲不是有一个参数cursor_sharing能快捷简单地解决问题,设置cursor_sharing=force, --//实际上合理的使用绑定变量才是王道. --//许多开发人员设置这个参数带来的各种bug,我第一次在8i下使用差点到处服务器cpu资源耗尽,好在我知道我当时的改动,修改回来一些正常. --//我当时还记得设置这个参数报ora-00600错误. --//我想起以前10g下遇到设置cur

[20171028]测试大量子光标对性能影响.txt

[20171028]测试大量子光标对性能影响.txt --//做一个测试例子说明存在大量子光标对性能影响. 1.环境: SCOTT@test01p> @ ver1 PORT_STRING                    VERSION        BANNER                                                                               CON_ID ------------------------------

[20160811]dbms_shared_pool清除子光标.txt

[20160811]dbms_shared_pool清除子光标.txt --工作需要,看了一下使用dbms_shared_pool包的purge清除子光标.顺便做一些细节测试看看: 1.环境与说明: SCOTT@test01p> @ ver1 PORT_STRING                    VERSION        BANNER                                                                            

[20160713]为什么光标不能共享.txt

[20160713]为什么光标不能共享.txt --这个是生产系统遇到的问题,有1条语句产生的子光标很多,但是直接查询v$sql仅仅有1个(CHILD_NUMBER很大). --检查为什么不能共享的原因是ROLL_INVALID_MISMATCH. ROLL_INVALID_MISMATCH reason indicates that, after a fresh statistics, using dbms_stats.auto_invalidate value for the paramet

[20171019]绑定变量的分配长度7.txt

[20171019]绑定变量的分配长度7.txt --//如果绑定变量中字符串分配占用空间的长度变化,oracle会建立子光标. --//参考连接: http://blog.itpub.net/267265/viewspace-1993495/ --//oracle 可以通过一个10503事件设置大的缓存,测试看看: $ oerr ora 10503 10503, 00000, "enable user-specified graduated bind lengths" // *Cau

[20170621]Session Cursor Caching 2.txt

[20170621]Session Cursor Caching 2.txt --//当sql执行时,第一次要经历硬分析,第二次软分析,如果session_cached_cursors设置的化,还可以绕过软分析,也有人叫"软软分析". --//摘录链接的一段话: --//www.toadworld.com/platforms/oracle/b/weblog/archive/2017/04/12/session-cursor-caching-part-one When a SQL sta