刷新 Shared_pool 与 dbms_shared_pool.keep

    一个使用了大量文本化SQL的系统运行了一段时间后,会出现共享池出现大量碎片,这时候共享池的性能会大大下降。在这种情况下,刷新共享池会恢复共享池的性能。
 
    使用下面的语句可以刷新共享池:
         ALTER SYSTEM FLUSH SHARED_POOL;
   
    要注意的时候,刷新共享池会使所有的没有使用DBMS_SHARED_POOL.KEEP固定的对象全部被清除,所以共享池刚刚刷新的时候,SQL和PL/SQL的执行效率会略微下降(需要重新装载和分析这些SQL和PL/SQL),不过很快系统的性能会提高并高于刷新前。

    要注意的是,对于没有使用KEEP过程固定的序列号发生器,如果这些序列号发生器使用了缓冲,那么这些缓冲会被刷新,可能会导致序列号跳号。
 
    The DBMS_SHARED_POOL package provides procedures that allow PL/SQL objects and SQL cursors to be pinned (kept) in the Oracle shared pool. Once pinned, objects are not subject to the normal aging-out processes of the shared pool。
   

    DBMS_SHARED_POOL is used primarily by DBAs to help solve memory management and performance issues that can arise when applications make use of large PL/SQL objects or SQL cursors. Two problems can arise when large objects need to be loaded into the shared pool:

  • ORA-04031 errors where insufficient memory is available and the user call fails to execute.

  • Degraded performance due to the memory management overhead involved in finding and making room to load large objects.

    Pinning large objects into the shared pool when the Oracle instance is first started can reduce or eliminate these problems. Some DBAs use DBMS_SHARED_POOL in their database startup scripts to help ensure that shared pool memory is used efficiently。

    The DBMS_SHARED_POOL package is created when the Oracle database is installed. The dbmspool.sql script. (found in the built-in packages source code directory, as described in Chapter 1 ) contains the source code for this package's specification. Unlike many of the other built-in package scripts, this script. is not called by catproc.sql . Thus, the DBA must manually build this package. This is accomplished by executing the dbmspool.sql and prvtpool.plb scripts (in order) from SQLDBA or Server Manager when connected as the INTERNAL user.

    Access to the DBMS_SHARED_POOL package is not automatically granted to any users, nor is a public synonym referencing the package created. The package is intended for use strictly by the Oracle DBA, usually when connected as the SYS user. Under Oracle8, the EXECUTE_CATALOG_ROLE role is granted EXECUTE privilege on DBMS_SHARED_POOL, so any users with this role can use the package.   

KEEP Procedure

This procedure keeps an object in the shared pool. Once an object has been kept in the shared pool, it is not subject to aging out of the pool. This may be useful for frequently used large objects. When large objects are brought into the shared pool, several objects may need to be aged out to create a contiguous area large enough.

Syntax

DBMS_SHARED_POOL.KEEP (
   name VARCHAR2, 
   flag CHAR      DEFAULT 'P');

Parameters

Table 97-3 KEEP Procedure Parameters

ParameterDescription

name

Name of the object to keep.

The value for this identifier is the concatenation of the address and hash_value columns from the v$sqlarea view. This is displayed by the SIZES procedure.

Currently, TABLE and VIEW objects may not be kept.

flag

(Optional) If this is not specified, then the package assumes that the first parameter is the name of a package/procedure/function and resolves the name.

Set to 'P' or 'p' to fully specify that the input is the name of a package/procedure/function.

Set to 'T' or 't' to specify that the input is the name of a type.

Set to 'R' or 'r' to specify that the input is the name of a trigger.

Set to 'Q' or 'q' to specify that the input is the name of a sequence.

In case the first argument is a cursor address and hash-value, the parameter should be set to any character except 'P' or 'p' or 'Q' or 'q' or 'R' or 'r' or 'T' or 't'.


SQL> @?/rdbms/admin/dbmspool.sql

程序包已创建。


授权成功。


视图已创建。


程序包体已创建。

SQL> @?/rdbms/admin/prvtpool.plb

视图已创建。


程序包体已创建。

准备工作做好后,就开始测试刷新共享与序列的试验:

SQL> create sequence seq_test;

序列已创建。

SQL> select seq_test.nextval from dual;

   NEXTVAL
----------
         1

SQL> alter system flush shared_pool;

系统已更改。

SQL> select seq_test.nextval from dual;

   NEXTVAL
----------
        21

表示,随着flush 共享池,sequence的cache被清空了。

接下来,已sysdba的身份连接数据库,把seq_test keep起来,再看看会发生什么情况。

SQL> exec dbms_shared_pool.keep('test.seq_test','q');

PL/SQL 过程已成功完成。

SQL>

再刷新共享池,看看情况。

SQL> select seq_test.nextval from dual;

   NEXTVAL
----------
        22

SQL> alter system flush shared_pool;

系统已更改。

SQL> select seq_test.nextval from dual;

   NEXTVAL
----------
        23

再用sysdba连接数据库,unkeep掉序列。

SQL> exec dbms_shared_pool.unkeep('test.seq_test','q');

PL/SQL 过程已成功完成。

再尝试刷新shared_pool。

SQL> select seq_test.nextval from dual;

   NEXTVAL
----------
        24

SQL> alter system flush shared_pool;

系统已更改。

SQL> select seq_test.nextval from dual;

   NEXTVAL
----------
        41

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

转载于:http://blog.itpub.net/9399028/viewspace-682402/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值