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. mac下git连接github远程仓库

    git配置 一.安装git 官方网站下载安装,如果有安装homebrew,在终端输入brew install git,安装后的位置在/Users/计算机用户名目录下安装完成后,在终端输入git --v ...

  2. Linux下keepalived配置

    1.背景 节点1:192.168.12.35 节点2:192.168.12.36 2.keepalived安装 使用yum仓库安装keepalived [root@node01 ~]# yum ins ...

  3. [日常摸鱼]Vijos1083小白逛公园-线段树

    题意:单点修改,询问区间最大子段和,$n\leq 5e5$ 考虑分治的方法$O(nlogn)$求一次最大子段和的做法,我们是根据中点分成左右两个区间,那么整个区间的答案要么是左边答案,要么是右边答案, ...

  4. 它听键盘声就知道你敲的是什么——GitHub 热点速览 Vol.51

    作者:HelloGitHub-小鱼干 本以为本周的 GitHub 和十二月一样平平无奇就那么度过了,结果 BackgroundMattingV2 重新刷新了本人的认知,还能这种骚操作在线实时抠视频去背 ...

  5. 【python爬虫】一个简单的爬取百家号文章的小爬虫

    需求 用"老龄智能"在百度百家号中搜索文章,爬取文章内容和相关信息. 观察网页 红色框框的地方可以选择资讯来源,我这里选择的是百家号,因为百家号聚合了来自多个平台的新闻报道.首先看 ...

  6. Python 设计模式——单例模式

    单例模式即确保类有且只有一个特定类型的对象,并提供全局访问点.因此通常用于日志记录.数据库操作.打印机后台处理程序等.这些程序在运行过程中只生成一个实例,避免对同一资源产生相互冲突的请求. 特点: 确 ...

  7. Viterbi算法

    clc;clear all;close all; Start_Pi = [-1,-1];State_k = ['H','L'];% 转移矩阵Transition_matrix = [-1,-1.322 ...

  8. Java基础进阶:时间类要点摘要,时间Date类实现格式化与解析源码实现详解,LocalDateTime时间类格式化与解析源码实现详解,Period,Duration获取时间间隔与源码实现,程序异常解析与处理方式

    要点摘要 课堂笔记 日期相关 JDK7 日期类-Date 概述 表示一个时间点对象,这个时间点是以1970年1月1日为参考点; 作用 可以通过该类的对象,表示一个时间,并面向对象操作时间; 构造方法 ...

  9. Jquery Ajax如何添加header参数

    转自网络 1 $.ajax({ 2 type: "POST", 3 url: "http://192.168.0.88/action.cgi?ActionID=WEB_R ...

  10. 【进程/作业管理】篇章一:Linux进程及其管理(系统监控类工具)----glances、dstat

    glances   dstat   glances命令详解 相对于htop工具的使用,这里介绍一下glances工具的使用,我个人是比较喜欢这款工具的,主要就是由于glances这款工具可以将系统状态 ...