ITPub博客

首页 > Linux操作系统 > Linux操作系统 > shared_pool——解决ORA-4031错误

shared_pool——解决ORA-4031错误

原创 Linux操作系统 作者:jx_yu 时间:2012-08-15 14:36:47 0 删除 编辑
~]$ oerr ora 4031
04031, 00000, "unable to allocate %s bytes of shared memory (\"%s\",\"%s\",\"%s\",\"%s\")"
// *Cause:  More shared memory is needed than was allocated in the shared
//          pool.
// *Action: If the shared pool is out of memory, either use the
//          dbms_shared_pool package to pin large packages,
//          reduce your use of shared memory, or increase the amount of
//          available shared memory by increasing the value of the
//          INIT.ORA parameters "shared_pool_reserved_size" and
//          "shared_pool_size".
//          If the large pool is out of memory, increase the INIT.ORA
//          parameter "large_pool_size". 
 
产生ORA-4031的原因:shared  pool不够用
         可能由于:1、硬解析太多
                             2、大SQL
 
解决方法:
            1、alter system flush shared_pool;     不能从根本上解决
                   说明:执行后会把library cache、row cache所有内容清空,
                               全部块都回到free中
                               接下来会产生大量的硬解析
             2、使用共享sql
                    a、使用绑定变量
                    b、统一书写风格
             3、将常见对象到共享池keep到shared pool中
                    select * from v$db_object_cache where sharable_mem >1000
                    and (type='PACKAGE' or type='PACKAGE BODY' or type='FUNCTION'     or type='PROCEDURE')  and kept='NO';
                      --查找消耗内存量大于1000的对象
                     执行dbms_shared_pool.keep('对象名'); 强行缓存到sql里面
                      DBMS_SHARED_POOL
                      @?/rdbms/admin/dbmspool.sql
              4、保留区
                     默认大小是共享池的5%。
                     它的大小可以通过参数SHARED_POOL_RESERVED_SIZE 来调整
                     Shared Pool 中内存大于4400 字节的SQL就会被存放在共享池的保留部分。而这个大小限制是通过隐含参_SHARED_POOL_RESERVED_MIN_ALLOC 来设定的(隐含参数不要去修改它)
                      select REQUEST_MISSES from v$shared_pool_reserved;
                                      --保留区中请求失败的次数,不为0,就意味着产生4031错误
                     增大shared_pool_reserved_size的值
               5、增加shared pool空间
              select COMPONENT,CURRENT_SIZE from V$SGA_DYNAMIC_COMPONENTS; 实际shared pool的大小
               show parameter sga_target
               show parameter sga_max_size                    限制sga_tartget的最大值
                alter system set shared_pool_size=150M scope=both; 若set小于oracle分配的值,会保留oracel字段分配的值
 
               

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

请登录后发表评论 登录
全部评论

注册时间:2012-05-23

  • 博文量
    80
  • 访问量
    876947