1. ORA-4031错误的原因,一般是大量的hard parse导致了shared pool中的free list中产生大量的内存小碎片,当一个需要很大内存来进行hard parse的sql语句到来时,无法从free list中找到内存,即使进行内存的释放,还是不能找到符合的内存块。从而报ORA-4031错误。


2. ORA-4031错误的解决方法:
1)alter system flush shared_pool;将shared pool中的所有内存清空。该方法治标不治本。
2)共享SQL语句:规范SQL语句的书写;使用绑定变量;找到没有使用绑定变量的SQL:
   select sql_fulltext from v$sql where executions=1 order by sql_text;
   如果在结果中发现一系列仅仅字面值不同的SQL,则可以修改cursor_sharing参数:
   alter system set cursor_sharing = 'force'; 来强制使用绑定变量。
3)使用shared pool中的保留区:
   select request_misses from v$shared_pool_reserved;
   如果结果大于0,则可以调大shared_pool_reserved的大小;
SQL> show parameter shared_pool
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
shared_pool_reserved_size            big integer 4M
shared_pool_size                     big integer 0

alter system set shared_pool_reserved=xxM scope=both;

4)使用dbms_shared_pool.keep('对象名')将使用内存很大的对象keep在内存中:
   先要执行:@?/rdbms/admin/dbmspool.sql
SQL> @?/rdbms/admin/dbmspool.sql
Package created.
Grant succeeded.
View created.
Package body created.

再查出需要keep的对象:
SQL> select owner,name,namespace,type,sharable_mem from v$db_object_cache where sharable_mem>10000
  2  and (type='PACKAGE' or type='PACKAGE BODY' or type='FUNCTION' or type='PROCEDURE') and kept='NO';

OWNER      NAME                      NAMESPACE          TYPE            SHARABLE_MEM
---------- ------------------------- ------------------ --------------- ------------
SYS        DBMS_BACKUP_RESTORE       TABLE/PROCEDURE    PACKAGE                33215
SYSMAN     EMD_COLLECTION            BODY               PACKAGE BODY           33233
SYS        DBMS_SHARED_POOL          BODY               PACKAGE BODY           12644
SYS        SYS$RAWTOANY              TABLE/PROCEDURE    FUNCTION               12640
SYSMAN     EMD_MAINTENANCE           TABLE/PROCEDURE    PACKAGE                29030
SYSMAN     EMD_MAINTENANCE           BODY               PACKAGE BODY           62930
SYSMAN     MGMT_JOB_ENGINE           BODY               PACKAGE BODY          218914
SYSMAN     EM_PING                   BODY               PACKAGE BODY           29086
SYS        DBMS_BACKUP_RESTORE       BODY               PACKAGE BODY           95519
SYSMAN     EMD_LOADER                TABLE/PROCEDURE    PACKAGE                12641
SYSMAN     EMD_LOADER                BODY               PACKAGE BODY           71861
SYS        PRVT_HDM                  BODY               PACKAGE BODY           43624
SYSMAN     MGMT_JOB_ENGINE           TABLE/PROCEDURE    PACKAGE                24938
SYS        STANDARD                  BODY               PACKAGE BODY           24960
SYSMAN     EM_SEVERITY_REPOS         BODY               PACKAGE BODY           33236
SYS        PRVT_ADVISOR              TABLE/PROCEDURE    PACKAGE                12640
SYSMAN     MGMT_GLOBAL               TABLE/PROCEDURE    PACKAGE                29902
SYS        DBMS_STANDARD             TABLE/PROCEDURE    PACKAGE                24929
SYS        DBMS_ADVISOR              BODY               PACKAGE BODY           25000
SYS        PRVT_HDM                  TABLE/PROCEDURE    PACKAGE                16732
SYS        PRVT_ADVISOR              BODY               PACKAGE BODY           66780
SYS        DBMS_RCVMAN               TABLE/PROCEDURE    PACKAGE                43295
SYS        STANDARD                  TABLE/PROCEDURE    PACKAGE               438648
SYS        DBMS_RCVMAN               BODY               PACKAGE BODY          375759

24 rows selected.

5)增加shared_pool_size的大小:
SQL> select component,current_size from v$sga_dynamic_components;

COMPONENT                                                        CURRENT_SIZE
---------------------------------------------------------------- ------------
shared pool                                                          75497472
large pool                                                            4194304
java pool                                                             4194304
streams pool                                                                0
DEFAULT buffer cache                                                130023424
KEEP buffer cache                                                           0
RECYCLE buffer cache                                                        0
DEFAULT 2K buffer cache                                                     0
DEFAULT 4K buffer cache                                                     0
DEFAULT 8K buffer cache                                                     0
DEFAULT 16K buffer cache                                                    0
DEFAULT 32K buffer cache                                                    0
ASM Buffer Cache                                                            0

13 rows selected.

sga_max_size:SGA允许的最大值,修改必须重启;
sga_target:必须小于sga_max_size, 表示当前SGA的最大值;
alter system set shared_pool_size=xxM scope=both;

3. 使用V$SHARED_POOL_ADVICE来设置shared pool的大小

V$SHARED_POOL_ADVICE displays information about estimated parse time in the shared pool for different pool sizes. The sizes range from 10% of the current shared pool size or the amount of pinned library cache memory (whichever is higher) to 200% of the current shared pool size, in equal intervals. The value of the interval depends on the current size of the shared pool.

Column Datatype Description
SHARED_POOL_SIZE_FOR_ESTIMATE NUMBER Shared pool size for the estimate (in megabytes)
SHARED_POOL_SIZE_FACTOR NUMBER Size factor with respect to the current shared pool size
ESTD_LC_SIZE NUMBER Estimated memory in use by the library cache (in megabytes)
ESTD_LC_MEMORY_OBJECTS NUMBER Estimated number of library cache memory objects in the shared pool of the specified size
ESTD_LC_TIME_SAVED NUMBER Estimated elapsed parse time saved (in seconds), owing to library cache memory objects being found in a shared pool of the specified size. This is the time that would have been spent in reloading the required objects in the shared pool had they been aged out due to insufficient amount of available free memory.
ESTD_LC_TIME_SAVED_FACTOR NUMBER Estimated parse time saved factor with respect to the current shared pool size
ESTD_LC_LOAD_TIME NUMBER Estimated elapsed time (in seconds) for parsing in a shared pool of the specified size
ESTD_LC_LOAD_TIME_FACTOR NUMBER Estimated load time factor with respect to the current shared pool size
ESTD_LC_MEMORY_OBJECT_HITS NUMBER Estimated number of times a library cache memory object was found in a shared pool of the specified size

可以使用下面的SQL语句来预估shared pool的大小:
select 'Shared Pool' component,shared_pool_size_for_estimate estd_sp_size,estd_lc_time_saved_factor parse_time_factor,case when current_parse_time_elapsed_s + adjustment_s<0
then 0 else current_parse_time_elapsed_s + adjustment_s end response_time
from (
select shared_pool_size_for_estimate,shared_pool_size_factor,estd_lc_time_saved_factor,a.estd_lc_time_saved,e.value/100
current_parse_time_elapsed_s,c.estd_lc_time_saved - a.estd_lc_time_saved adjustment_s from v$shared_pool_advice a,
(select * from v$sysstat where name='parse time elapsed') e,
(select estd_lc_time_saved from v$shared_pool_advice where shared_pool_size_factor=1) c
);
COMPONENT   ESTD_SP_SIZE  PARSE_TIME_FACTOR  RESPONSE_TIME
--------------    -----------------  -------------------------   -------------
Shared Pool           64             .9989                          294.37
Shared Pool           72                 1                            257.37
Shared Pool           80            1.0009                         226.37
Shared Pool           88            1.0016                         201.37
Shared Pool           96            1.0022                         181.37
Shared Pool          104            1.0027                        166.37
Shared Pool          112            1.0029                        156.37
Shared Pool          120            1.0032                        149.37
Shared Pool          128            1.0033                        144.37
Shared Pool          136            1.0034                        141.37
Shared Pool          144            1.0034                        139.37

11 rows selected.

转自:http://blog.chinaunix.net/uid-25909722-id-3380385.html

【ORA】ORA-4031错误分析和解决办法的更多相关文章

  1. 关于COM类工厂80070005和8000401a错误分析及解决办法

    关于COM类工厂80070005和8000401a错误分析及解决办法 看到很多相关的文章,第一次配置配置时没有啥作用,让别人来解决的,可惜不晓得他怎么解决的,当我再次遇到时,不得不硬着头皮去解决. 总 ...

  2. plsql在64位机器下读取tnsname.ora 及oracle_home异常的解决办法

    问题是: 我在自己电脑(win7  64bit)上安装了oracle的64位数据库   通过sqlplus能正常连接 主要是安装pl/sql时   我是这样安装的1.在网上下载了个instantcli ...

  3. 另一个 OleDbParameterCollection 中已包含 OleDbParameter 错误分析及解决办法

    程序非常简单,就是从一个表中取出一个符合要求的数据,如果取到,就把该数据对应的计数加1.也就是执行不同的两个SQL语句操作同一个表,并且这两个SQL的参数是一样的.在一个函数里完成这个调用.执行第二个 ...

  4. DotNetCore.1.0.1-VS2015Tools.Preview2.0.2 安装错误分析及解决办法(so far)

    折腾了这么多天总算弄完了,真恶心.为了让其他童靴避免掉进我遇到的坑里,我决定把最近遇到问题及其解决办法总结一下,希望对大家有帮助. 1.对于2016年7月底以前安装VS用户来说,可能不会那么迫切安装这 ...

  5. PLSQL Developer概念学习系列之登录连接Oracle时出现(没有登录) -PL / SQL Developer:ORA - 12541: TNS :无建听程序的错误解决办法(图文详解)

    不多说,直接上干货! 前期博客 PLSQL Developer概念学习系列之如何正确登录连接上Oracle(图文详解)   如用scott.scott_password进行登录,orcl是全局数据库 ...

  6. 【ORA】ORA-39002,ORA-39070,ORA-29283, ORA-06512,ORA-29283解决办法

    今天使用IMPDP导入的时候报了一个错误 ORA-39002: invalid operation  ORA-39070: Unable to open the log file.  ORA-2928 ...

  7. Error:The network adaptor could not establish the connection问题的解决办法

     最近在学习hibernate 5.0.4, 自然而然就需要使用数据库,由于本人工作中一直使用Oracle,于是在自己的电脑上安装了Oracle 12.1.0, 安装完成使用一直没有问题,突然有一天使 ...

  8. Loadrunner参数化连接oracle、mysql数据源报错及解决办法

    Loadrunner参数化连接oracle.mysql数据源报错及解决办法 (本人系统是Win7 64,  两位小伙伴因为是默认安装lr,安装在 最终参数化的时候,出现连接字符串无法自动加载出来: 最 ...

  9. Oracle ORA-01033: ORACLE initialization or shutdown in progress 错误解决办法

    Oracle ORA-01033: ORACLE initialization or shutdown in progress 错误解决办法 登陆数据库时提示 “ORA-01033”错误在命令窗口以s ...

随机推荐

  1. Fastjson 1.2.47 远程命令执行漏洞复现

    前言 这个漏洞出来有一段时间了,有人一直复现不成功来问我,就自己复现了下,顺便简单记录下这个漏洞原理,以便后面回忆. 复现过程 网上已经有很多文章了,这里就不在写了.主要记录一下复现过程中遇到的问题 ...

  2. jvm基本结构和解析

    jvm的基本结构图如下 这只是代表我的个人理解  不是很深刻  欢迎各类大神进行补充和纠正 jvm之所以强大就是因为他从软件层面屏蔽不用操作系统在底层硬件与指令上的区别,从而可以在不同系统上兼容 主要 ...

  3. dataframe的一些用法

    pandas中Dataframe的一些用法 pandas读取excel文件 pd.read_excel 前提是安装xlrd库 dataframe,numpy,list之间的互相转换 dataframe ...

  4. 持续引领大数据行业发展,腾讯云发布全链路数据开发平台WeData

    9月11日,在腾讯全球数字生态大会大数据专场上,腾讯云大数据产品副总经理雷小平重磅发布了全链路数据开发平台WeData,同时发布和升级了流计算服务.云数据仓库.ES.企业画像等6款核心产品,进一步优化 ...

  5. cloudera集群开启kerberos认证后,删除zk中的/hbase目录

    问题 在cdh集群中开启了kerberos认证,hbase集群出现一点问题,需要通过zookeeper-client访问zookeeper,删除/hbase节点时候报错:Authentication ...

  6. 用burp爆破tomcat的过程

    首先burp抓包,将抓到的包放到intruder中 通过burp中自带的解码得知账号密码中有个":"号 所以我们选择的数据类型为Custom iterator 第二条输入" ...

  7. luabind 使用

    LuaBind --最强大的Lua C++ Bind 转载:http://www.cppblog.com/deane/articles/49208.html1 介绍LuaBind 是一个帮助你绑定C+ ...

  8. [.NET] - EventLog.EntryWritten Event

    刚看到在MSND论坛上有人问一个EventLog.EntryWritten Event相关的问题,说是在2015触发了一个2013年的EventWritten的事件,比较好奇,然后查看了下这个类: h ...

  9. Json串的字段如果和类中字段不一致,如何映射、转换?

    Json串是我们现在经常会遇到的一种描述对象的字符串格式.在用Java语言开发的功能中,也经常需要做Json串与Java对象之间的转换. fastjson就是经常用来做Json串与Java对象之间的转 ...

  10. Omega System Trading and Development Club内部分享策略Easylanguage源码

    更多精彩内容,欢迎关注公众号:数量技术宅.关于本期分享的任何问题,请加技术宅微信:sljsz01 关于 Omega System Trading and Development Club " ...