How to Pin a Cursor in the Shared Pool using DBMS_SHARED_POOL.KEEP (文档 ID 726780.1)

In this Document

 Goal
 Fix
 References

APPLIES TO:

Oracle Server - Enterprise Edition - Version 8.0.3.0 and later
Oracle Server - Personal Edition - Version 8.0.3.0 and later
Oracle Server - Standard Edition - Version 8.0.3.0 and later
Information in this document applies to any platform.

GOAL

This document shows how to pin a single cursor in the shared pool.

FIX

For various reasons, primarily the re-loading of a cursor due to aging out, it may be necessary to pin an individual cursor in the shared pool.  Thus, prevent the reload, avoid  re-parsing  and the regeneration of the access path for a query etc.
 


A cursor can be pinned using the address and the hash_value of the cursor which can be found in the V$SQL view. To  identify the cursor a select can be used similar to:

select address,hash_value 
from v$sql
where sql_text like '%&IDENTIFIABLE_SQL_TEXT%';

Example output:

ADDRESS HASH_VALUE 
-------- ---------- 
310E6C4C 2745775928

Then the address and hash value to KEEP the cursor in the shared pool as follows:

exec DBMS_SHARED_POOL.KEEP( '310E6C4C,2745775928' , 'C' );

Where:

  • 310E6C4C is the ADDRESS from the select in question
  • 2745775928 is the HASH_VALUE from the select in question
  • 'C' identifier can be any any character except 'P' or 'p' or 'Q' or 'q' or 'R' or 'r' or 'T' or 't'.

So, by way of a worked example, say I have a SQL statement:

SELECT 'Example SQL' FROM dual;

I would need to find something identifiable about this SQL to search on in order to find the address and hash_value.
In this case I have chosen the "Example SQL" phrase , but in your SQL you will likely need to use something else.

Once I have decided some identifier, I issue the following:

SELECT SUBSTR(sql_text,1,30) Text,address,hash_value
FROM v$sql
WHERE sql_text LIKE '%Example SQL%'
/

TEXT                           ADDRESS          HASH_VALUE KEPT_VERSIONS
------------------------------ ---------------- ---------- -------------
SELECT 'Example SQL' FROM dual 0000000391908750 1869363365             0
SELECT SUBSTR(sql_text,1,30) T 000000038B5DBA70  504353775             0

We are interested in HASH_VALUE '1869363365'.
(HASH_VALUE 504353775 is the select from v$sql which is returned as it also contains the string.)
Note that the KEPT_VERSIONS 'flag' is 0 at this point.
If we 'KEEP' the cursor using:

exec DBMS_SHARED_POOL.KEEP('0000000391908750,1869363365','C');

PL/SQL procedure successfully completed.

Then the KEPT_VERSIONS is set to '65' indicating it is being kept:

select substr(sql_text,1,30) Text,address,hash_value,KEPT_VERSIONS
from v$sql
where sql_text like '%Example SQL%'
/

TEXT                           ADDRESS          HASH_VALUE KEPT_VERSIONS
------------------------------ ---------------- ---------- -------------
SELECT 'Example SQL' FROM dual 0000000391908750 1869363365            65
SELECT SUBSTR(sql_text,1,30) T 000000038B5DBA70  504353775             0



If we UNKEEP the Cursor using:

exec DBMS_SHARED_POOL.UNKEEP('0000000391908750,1869363365','C');

PL/SQL procedure successfully completed.



Then the KEPT_VERSIONS is restored:

TEXT                           ADDRESS          HASH_VALUE KEPT_VERSIONS
------------------------------ ---------------- ---------- -------------
SELECT 'Example SQL' FROM dual 0000000391908750 1869363365             0
SELECT SUBSTR(sql_text,1,30) T 000000038B5DBA70  504353775             0

 You can also see the kept status in v$db_object_cache:

 
SELECT substr( name,1,30) NAME, type, kept
 FROM v$db_object_cache
 WHERE  name like '%Example SQL%'
 /

NAME                                   TYPE                                                  KEP
-------------------------------------- ----------------------------------------------------- ---
SELECT 'Example SQL' FROM dual CURSOR                                                        YES
SELECT 'Example SQL' FROM dual CURSOR                                                        YES

For details of the package, see:

Oracle® Database PL/SQL Packages and Types Reference
11g Release 2 (11.2)

Part Number E25788-04
Chapter  132 DBMS_SHARED_POOL
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_shared_pool.htm#ARPLS055

In order to pin multiple statements in the shared pool, perhaps based upon the number of times a cursor is executed, See:

Document 130699.1 How to Reduce LIBRARY CACHE LATCH Contention with Pin Cursor Procedure

REFERENCES

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值