你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle Shared pool 详解

[日期:2011-07-28] 来源:Linux社区  作者:tianlesoftware [字体:大 中 小]

5.2.2 ACTION

(1)KEEPING OBJECTS

            The primary source of problems is large PL/SQL objects. The means of correcting these errors is to 'keep” large PL/SQL objects in the shared pool at startup time. This will load the objects into the shared pool and will make sure that the objects are never aged out of the shared pool. If the objects are never aged out then there will not be a problem with trying to load them and not having enough memory.

            Objects are 'kept' in the shared pool using the dbms_shared_pool package that is defined in the dbmspool.sql file. For example:

            exec dbms_shared_pool.keep('SYS.STANDARD');

 

            All large packages that are shipped should be 'kept' if the customer uses PL/SQL. This includes 'STANDARD', 'DBMS_STANDARD', and 'DIUTIL'. All large customer packages should also be marked 'kept'.

            One restriction on the 'keep' procedure is that it only works on packages. If the customer has large procedures or large anonymous blocks, then these will need to be put into packages and marked kept.

 

            You can determine what large stored objects are in the shared pool by selecting from the V$DB_OBJECT_CACHE fixed view. This will also tell you which objects have been marked kept. This can be done with the following query:

           

/* Formatted on 2011/6/22 13:13:23 (QP5 v5.163.1008.3004) */

SELECT *

  FROM V$DB_OBJECT_CACHE

 WHERE sharable_mem > 10000;

 

 

            Note that this query will not catch PL/SQL objects that are only rarely used and therefore the PL/SQL object is not currently loaded in the shared pool.

 

            To determine what large PL/SQL objects are currently loaded in the shared pool, are not marked ‘kept’, and therefore may cause a problem, execute the following:

 

/* Formatted on 2011/6/22 13:14:25 (QP5 v5.163.1008.3004) */

SELECT name, sharable_mem

  FROM V$DB_OBJECT_CACHE

 WHERE sharable_mem > 10000

       AND (   TYPE = 'PACKAGE'

            OR TYPE = 'PACKAGE BODY'

            OR TYPE = 'FUNCTION'

            OR TYPE = 'PROCEDURE')

       AND kept = 'NO';

 

(2)USE BIND VARIABLES

            Another thing that can be done to reduce the amount of fragmentation is to reduce or eliminate the number of SQL statements in the shared pool that are duplicates of each other except for a constant that is embedded in the statement. The statements should be replaced with one statement that uses a bind variable instead of a constant.

 

For example:

            select * from emp where empno=1;

            select * from emp where empno=2;

            select * from emp where empno=3;

Should all be replaced with:

            select * from emp where empno=:1;

 

            You can identify statements that potentially fall into this class with a query like the following:

 

/* Formatted on 2011/6/22 13:18:04 (QP5 v5.163.1008.3004) */

  SELECT SUBSTR (sql_text, 1, 30) sql, COUNT (*) copies

    FROM v$sqlarea

GROUP BY SUBSTR (sql_text, 1, 30)

  HAVING COUNT (*) > 3;

 

(3)MAX  BIND  SIZE

            It is possible for a sql statement to not be shared because the max bind variable lengths of the bind variables in the statement do not match. This is automatically taken care of for precompiler programs and forms programs, but could be a problem for programs that directly use OCI. The bind call in OCI takes two arguments, one is the max length of the value, and the other is a pointer to the actual length. If the current length is always passed in as the max length instead of the max possible length for the variable, then this could cause the sql statement not to be shared.

            To identify statements that might potentially have this problem execute the following statement:

 

/* Formatted on 2011/6/22 13:22:20 (QP5 v5.163.1008.3004) */

SELECT sql_text, version_count

  FROM v$sqlarea

 WHERE version_count > 5;

 

(4)ELIMINATING LARGE ANONYMOUS PL/SQL

            Large anonymous PL/SQL blocks should be turned into small anonymous PL/SQL blocks that call packaged functions. The packages should be 'kept' in memory.            This includes anonymous PL/SQL blocks that are used for trigger definitions. Large  anonymous blocks can be identifie d with the following query:

 

/* Formatted on 2011/6/22 13:25:22 (QP5 v5.163.1008.3004) */

SELECT sql_text

  FROM v$sqlarea

 WHERE command_type = 47                   -- command type for anonymous block

AND LENGTH (sql_text) > 500;

 

            Note that this query will not catch PL/SQL blocks that are only rarely used and therefore the PL/SQL block is not currently loaded in the shared pool.

 

            Another option that can be used when an anonymous block cannot be turned into a package is to mark the anonymous block with some string so that it can be identified in v$sqlarea and marked 'kept'.

 

For example, instead of using

/* Formatted on 2011/6/22 13:33:20 (QP5 v5.163.1008.3004) */

DECLARE

   x   NUMBER;

BEGIN

   x := 5;

END;

 

one can use:

/* Formatted on 2011/6/22 13:33:34 (QP5 v5.163.1008.3004) */

DECLARE          /* KEEP_ME */

   x      NUMBER;

BEGIN

   x := 5;

END;

 

            You can then use the following procedure to select these statements out of the shared pool and mark them 'kept' using the dbms_shared_pool.keep package.

 

 

/* Formatted on 2011/6/22 13:34:55 (QP5 v5.163.1008.3004) */

DECLARE

   /* DONT_KEEP_ME */

   addr   VARCHAR2 (10);

   hash   NUMBER;

   CURSOR anon

   IS

      SELECT address, hash_value

        FROM v$sqlarea

       WHERE     command_type = 47         -- command type for anonymous block

             AND sql_text LIKE '% KEEP_ME %'

             AND sql_text NOT LIKE '%DONT_KEEP_ME%';

BEGIN

   OPEN anon;

   LOOP

      FETCH anon

      INTO addr, hash;

      EXIT WHEN anon%NOTFOUND;

      DBMS_SHARED_POOL.keep (addr || ',' || TO_CHAR (hash), 'C');

   END LOOP;

END;

 

            To create DBMS_SHARED_POOL, run the DBMSPOOL.SQL script. The PRVTPOOL.PLB script is automatically executed after DBMSPOOL.SQL runs. These scripts are not run by as part of standard database creation.

 

5.3 Initialization Parameters

            The following Oracle initialization parameters have an important impact on library cache and shared pool performance.

 

(1).  _KGL_BUCKET_COUNT

(2).  _KGL_LATCH_COUNT

(3).  cursor_sharing

(4).  shared_pool_size

(5).  shared_pool_reserved_size

(6).  shared_pool_reserved_min_alloc

(7).  large_pool_size

(8).  large_pool_min_alloc

(9).  parallel_min_message_pool

(10).                      backup_io_slaves

(11).                      temporary_table_locks

(12).                      dml_locks

(13).                      sequence_cache_entries

(14).                      row_cache_cursors

(15).                      max_enabled_roles

(16).                      mts_dispatchers

(17).                      mts_max_dispatchers

(18).                      mts_servers

(19).                      mts_max_servers

(20).                      cursor_space_for_time

linux
相关资讯       Oracle教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款