博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[20160201]db_link与子光标问题.txt
阅读量:6718 次
发布时间:2019-06-25

本文共 4670 字,大约阅读时间需要 15 分钟。

[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]

转载地址:http://wfymo.baihongyu.com/

你可能感兴趣的文章
[LintCode] Integer to Roman 整数转化成罗马数字
查看>>
日期控件
查看>>
mysql 如何修改、添加、删除表主键
查看>>
【Maven】3.使用IntelliJ IDEA 使用本地搭建的maven私服,而不是使用默认的maven设置...
查看>>
Navi.Soft31.WinForm框架(含下载地址)
查看>>
Charles配置抓包HTTP,HTTPS
查看>>
[Everyday Mathematics]20150109
查看>>
RSA(非对称加密算法、公钥加密算法)
查看>>
一个执行计划异常变更的案例 - 外传之SQL AWR
查看>>
获取 metadata 过程详解 - 每天5分钟玩转 OpenStack(167)
查看>>
WinCE及Windows软件开发相关书籍转让
查看>>
python接口自动化10-token登录
查看>>
MYSQL中约束及修改数据表
查看>>
EntityFramework Core Raw Query再叙注意事项后续
查看>>
初识gd库
查看>>
shell下office、html、pdf文档互转方法
查看>>
Shell编程基础篇-下
查看>>
OpenShift中的持续交付
查看>>
以操作系统的角度述说线程与进程
查看>>
STL - 容器 - Map(一)
查看>>