遇到ORA-4031错误时。你的心里会不会发怵?ORA-4031非常easy导致数据库出现异常崩溃,当Oracle的核心进程无法获得共享池内存时。它们会把数据库异常宕掉。当然,ORA-4031就像黄灯一样,它在提醒你须要立即採取紧急策略了。不是说它一出现,数据库立即就会宕机。

话题讨论:

1.ORA-4031是Oracle中最令人厌恶的报错,它的出现有哪几种原因?



2.一旦出现4031错误。也就是说共享池内存不足的情况下,我们该怎样释放内存呢?你有木有遇到过对应的情形呢?请回顾下当时是怎样解决的?



3.有一句俗语叫丢车保帅。运行计划是SQL核心关键所在。是否意味着在释放内存时,不应该覆盖运行计划这部分?当运行计划部分占用内存比較多时,怎样优化呢?

4.消耗共享池内存的主要有两种对象,一种是SQL,而是存储过程、函数、包等这类可运行对象。当遇到4031错误时,您认为须要优先释放哪种对象

问题分析:

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:
   假设在结果中发现一系列只字面值不同的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.


ORA-4031错误 解决方法的更多相关文章

  1. SQL SERVER 9003错误解决方法 只适用于SQL2000

    SQLSERVER 9003错误解决方法 只适用于SQL2000 (只适用于SQL2000) "无法打开新数据库 'POS'.CREATE DATABASE 中止. (Microsoft S ...

  2. New XAMPP security concept:错误解决方法

    New XAMPP security concept:错误解决方法 (2014-03-06 16:07:46) 转载▼   分类: php 在Linux上配置xampp后远程访问域名报错: New X ...

  3. hadoop本地库与系统版本不一致引起的错误解决方法

    hadoop本地库与系统版本不一致引起的错误解决方法 部署hadoop的集群环境为 操作系统 centos 5.8 hadoop版本为cloudera   hadoop-0.20.2-cdh3u3 集 ...

  4. mysql Access denied for user root@localhost错误解决方法总结(转)

    mysql Access denied for user root@localhost错误解决方法总结(转) mysql Access denied for user \'root\'@\'local ...

  5. Eclipse 出现Some sites could not be found. See the error log for more detail.错误 解决方法

    Eclipse 出现Some sites could not be found.  See the error log for more detail.错误 解决方法 Some sites could ...

  6. eWebeditor编辑器上传图片路径错误解决方法[疑难杂症]【转,作者:unvs】

    做了一个多版本的网站,后台用的编辑器是eWebeditor,NET版,后面发现上传图片或者文件之后,路径错误无法显示,必须手工修改才行.. 为了更清楚的说明问题,我下面会说的比较详细,首先是网站文件框 ...

  7. 网站启动SSL, http变为https后,session验证码错误解决方法

    网站启动SSL, http变为https后,session验证码错误解决方法   最近公司需要后台启动安全证书,证书安装完毕后,后台老提示 验证码错误,经过几天的研究,此问题已经得到有效解决,现把方法 ...

  8. Oracle OCI-22053:溢出错误解决方法

    原文 Oracle OCI-22053:溢出错误解决方法 Oracle 数值数据类型最多可存储 38 个字节的精度.当将 Oracle 数值转换为公共语言运行库数据类型时,小数点后边的位数可能过多,这 ...

  9. Nginx出现“413 Request Entity Too Large”错误解决方法

    Nginx出现“413 Request Entity Too Large”错误解决方法 2011-03-25 13:49:55|  分类: 默认分类 |  标签:413  request  entit ...

  10. CAS SSO:汇集配置过程中的错误解决方法

    本教程为gevin.me原创文章,转载请注明: CAS SSO:配置过程中的错误解决方法 | Gevin’s Blog 本文将收集在配置CAS SSO遇到的所有错误,希望对大家有帮助,也方便下次搭建的 ...

随机推荐

  1. Redis允许远程连接

    默认安装启动redis后,只能本地连接,无法远程连接上,原因是redis安全策略默认本机访问,所以远程访问的话需要将 配置文件redis.cof 中的 bind 127.0.0.1 前面的#注释掉, ...

  2. 7. 关于IntelliJ IDEA删除项目

    转自:https://www.cnblogs.com/zhangqian27/p/7698148.html 刚开始使用IDEA . 自己创建项目玩,结果发现IDEA无法删除,我也是醉了,Eclipse ...

  3. [GDKOI2010] 圈地计划(网络流)

    题2链接:https://www.luogu.org/problemnew/show/P1935 Description 最近房地产商GDOI(Group of Dumbbells Or Idiots ...

  4. vue -- 7 个 有用的 Vue 开发技巧

    1 状态共享 随着组件的细化,就会遇到多组件状态共享的情况, Vuex当然可以解决这类问题,不过就像 Vuex官方文档所说的,如果应用不够大,为避免代码繁琐冗余,最好不要使用它,今天我们介绍的是 vu ...

  5. 使用 Spring HATEOAS 开发 REST 服务--转

    原文地址:https://www.ibm.com/developerworks/cn/java/j-lo-SpringHATEOAS/index.html?ca=drs-&utm_source ...

  6. VS自定义开发向导中的vsdir文件的简单说明

    作者:朱金灿 来源:http://blog.csdn.net/clever101 VS自定义开发向导中有一个vsdir文件.这个文件指定了在VS中项目的标题.默认工程名等内容.下面对vsdir文件做一 ...

  7. XRDP与VNC的关系(转载)

    XRDP与VNC的关系 如果仅仅安装XRDP协议.是不能在windows上使用远程桌面连接到Ubuntu. 还须要安装VNCServer才行. 所以,XRDP启动之后.系统会自己主动启动一个VNC会话 ...

  8. CSS命令

    border-bottom-right-radius: 10px;/* 文本框的角的弯曲度*/ border-bottom-left-radius: 10px; border-top-left-rad ...

  9. appium使用教程(三)-------------用例编写

    1. 驱动 import os, time, unittest from appium import webdriver PATH = lambda p:os.path.abspath(os.path ...

  10. NOIP 2012 疫情控制(二分+贪心+倍增)

    题解 二分时间 然后一个显然的事是一个军队向上爬的越高它控制的点越多 所以首先军队尽量往上爬. 当一个军队可以爬到根节点我们记录下它的剩余时间T和它到达根结点时经过的根节点的子节点son. 当一个军队 ...