今天遇到一起ORACLE数据库宕机案例,下面是对这起数据库宕机案例的原因进行分析、解读。分析过程中顺便记录一下这个案例的前因后果,攒点经验值,培养一下分析、解决问题的能力。

案例环境:

 

操作系统 :Oracle Linux Server release 5.7 64 bit

数据库版本:Oracle Database 10g Release 10.2.0.4.0 - 64bit Production

案例分析:

收到告警去检查数据库时,发现实例已经宕机。检查告警日志,发现下面错误信息:

ORA-00604: error occurred at recursive SQL level 1

ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","select count(*) from sys.job...","sql area","tmp")

Mon Nov  2 11:43:00 2015

Errors in file /u01/app/oracle/admin/SCM2/bdump/scm2_cjq0_6571.trc:

ORA-00604: error occurred at recursive SQL level 1

ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","select job, nvl2(last_date, ...","sql area","tmp")

Mon Nov  2 11:43:00 2015

Errors in file /u01/app/oracle/admin/SCM2/bdump/scm2_cjq0_6571.trc:

ORA-00604: error occurred at recursive SQL level 1

ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","select count(*) from sys.job...","sql area","tmp")

Mon Nov  2 11:43:05 2015

Errors in file /u01/app/oracle/admin/SCM2/bdump/scm2_cjq0_6571.trc:

ORA-00604: error occurred at recursive SQL level 1

ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","select job, nvl2(last_date, ...","sql area","tmp")

Mon Nov  2 11:43:05 2015

Errors in file /u01/app/oracle/admin/SCM2/bdump/scm2_cjq0_6571.trc:

ORA-00604: error occurred at recursive SQL level 1

ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","select count(*) from sys.job...","sql area","tmp")

Mon Nov  2 11:43:08 2015

Errors in file /u01/app/oracle/admin/SCM2/bdump/scm2_reco_6569.trc:

ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","select host,userid,password,...","sql area","tmp")

Mon Nov  2 11:43:08 2015

RECO: terminating instance due to error 4031

Mon Nov  2 11:43:08 2015

Errors in file /u01/app/oracle/admin/SCM2/bdump/scm2_pmon_6555.trc:

ORA-04031: unable to allocate  bytes of shared memory ("","","","")

Instance terminated by RECO, pid = 6569

从告警日志我们可以看到ORA-00604与ORA-04031错误导致了这次宕机事故(RECO: terminating instance due to error 4031):

$ 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-04031错误可能由两个原因引起:

1:内存中存在大量碎片,导致在分配内存的时候,没有连续的内存可存放,此问题一般是需要在开发的角度上入手,比如增加绑定变量,减少硬解析来改善和避免;

2.内存容量不足,需要扩大内存。

这台机器分配的物理内存为8G,结果检查发现SGA只分配了1168M,不到2G,瞬时碉堡了。此时真是很无语。ASH Report分析宕机前后的Buffer Cache和Shared Pool大小如下所示。

查看跟踪文件,可以看到SGA: allocation forcing component growth等待事件,可以确认的是由于SGA无法增长导致,也就是SGA被撑爆了,结合ASH Report我们可以看到当时Shared Pool的大小已经接近SGA的69.6%大小。

SO: 0xa617d9c0, type: 4, owner: 0xa8a26c68, flag: INIT/-/-/0x00

  (session) sid: 932 trans: (nil), creator: 0xa8a26c68, flag: (51) USR/- BSY/-/-/-/-/-

            DID: 0001-000A-00000003, short-term DID: 0000-0000-00000000

            txn branch: (nil)

            oct: 0, prv: 0, sql: (nil), psql: (nil), user: 0/SYS

  last wait for 'SGA: allocation forcing component growth' blocking sess=0x(nil) seq=51324 wait_time=10714 seconds since wait started=0

          =0, =0, =0

  Dumping Session Wait History

   for 'SGA: allocation forcing component growth' count=1 wait_time=10714

          =0, =0, =0

   for 'SGA: allocation forcing component growth' count=1 wait_time=10512

          =0, =0, =0

   for 'latch: shared pool' count=1 wait_time=892

          address=600e7320, number=d6, tries=0

   for 'latch: shared pool' count=1 wait_time=28

          address=600e7320, number=d6, tries=0

   for 'latch: shared pool' count=1 wait_time=51

          address=600e7320, number=d6, tries=0

   for 'latch: shared pool' count=1 wait_time=114

          address=600e7320, number=d6, tries=0

   for 'latch: shared pool' count=1 wait_time=120

          address=600e7320, number=d6, tries=0

   for 'latch: library cache' count=1 wait_time=33

          address=a3fa46e8, number=d7, tries=1

结合上面的一些分析,可以断定SGA的不合理设置导致shared pool的内存被全部耗尽,SGA被撑爆了。于是调整SGA的参数才是解决问题的正确对策。另外考虑到这个数据库也正常运行了较长一段时间,也分析了一下awr、addm报告,发现系统的硬解析相当严重。另外通过下面脚本观察了一段时间shared pool的变化,发现其收缩、增长较频繁。

 

SELECT start_time, 

       component, 

       oper_type, 

       oper_mode, 

       initial_size / 1024 / 1024 "INITIAL", 

       final_size / 1024 / 1024   "FINAL", 

       end_time 

FROM   v$sga_resize_ops 

WHERE  component IN ( 'DEFAULT buffer cache', 'shared pool' ) 

       AND status = 'COMPLETE' 

ORDER  BY start_time, 

          component; 

这个可以通过设置数据库参数SHARED_POOL_SIZE,保证SHARED_POOL_SIZE大小不会由于内存紧张而低于这个大小,另外可以设置SGA resize的时间间隔

ALTER SYSTEM SET “_memory_broker_stat_interval”=n SCOPE=SPFILE;

问题虽然解决了,但是真正需要反思的是为什么这个SGA_MAX_SIZE设置为1168M大小的事情!而且没有在巡检当中被发现。

 

参考资料:

http://blog.csdn.net/wenzhongyan/article/details/29866845

http://blog.chinaunix.net/uid-20802110-id-4188357.html

http://www.oraclefreebase.com/blog/2015/10/%E6%95%B0%E6%8D%AE%E5%BA%93ora-4031%E6%95%B0%E6%8D%AE%E5%BA%93crash/

ORA-04031错误导致宕机案例分析的更多相关文章

  1. Linux服务器宕机案例一则

    案例环境 操作系统 :Oracle Linux Server release 5.7 64bit 虚拟机 硬件配置 : 物理机型号为DELL R720 资源配置 :RAM 8G Intel(R) Xe ...

  2. Solr4.8.0源码分析(26)之Recovery失败造成的宕机原因分析

    最近在公司做SolrCloud的容灾测试,刚好碰到了一个比较蛋疼的问题,跟SolrCloud的Recovery和leader选举有关,正好拿出来分析下. 现象是这样的:比如我有一台3个shard的So ...

  3. Centos7.5调试/etc/sysctl.conf文件导致宕机

    今天安装greenplus数据库,需要调试一个核心文件/etc/sysctl.conf文件,结果导致系统异常宕机,出现的问题就是使用任何命令都不能输出正确的结果,只有这个显示: 不知道是什么原因,ls ...

  4. Hadoop 服务SYS CPU过高导致宕机问题

    最近某hadoop集群多次出现机器宕机,现象为瞬间机器的sys cpu增长至100%,机器无法登录.只能硬件重启,ganglia cpu信息如下: 首先怀疑有用户启动了比较奇葩的job,导致不合理的系 ...

  5. rac库grid目录权限(6751)导致数据库宕机案例 此方法仅用于紧急救助

    问题: 我的rac环境不小心通过chown命令改变了/u01目录及其子目录的权限,导致rac节点2数据库宕掉,sqlplus下打开数据库报错如下: [oracle@node2 ~]$ sqlplus ...

  6. MySQL Bug导致异常宕机的分析流程

    原文链接:http://click.aliyun.com/m/42521/ 摘要: 本文主要通过一个bug来记录一下如何分析一个MySQL bug的崩溃信息. 版本:Percona 5.7.17-11 ...

  7. Linux服务器宕机案例第二则

    邮件告警发现海外工厂一Linux服务器连接不上,DPA(Database Performance Analyzer)系统也发现其出现问题,ping这台服务器发现网络不通,联系不到当地系统管理员,邮件咨 ...

  8. pt-osc改表导致数据不一致案例分析

    2016-06-10 李丹 dba流浪猫 我们平时除了解决自己问题外,有时候也会协助圈内人士,进行一些故障排查,此案例就是帮某公司DBA进行的故障分析,因为比较典型,特分享一下,但仅仅是分享发生的过程 ...

  9. AZURE云上 mkfs.ext4 /dev/sdc 导致宕机问题解决纪实

    )开机启动挂载配置 [root@pldb2 ~]# vim /etc/fstab You have new mail in /var/spool/mail/root [root@pldb2 ~]# m ...

随机推荐

  1. ASP.NET MVC 网站开发总结(一)

    历经一个多月的努力,工作室的门户网站(http://www.wingstudio.org)终于结束了内部公测. 仔细算一下,大概把网站开发出1.0版本大概用了一个月的时间(主要是利用课余时间),其后大 ...

  2. XE7 iOS 取得系统字型名称

    系统字型名称在每个平台的取得方式不尽相同,以下示范如何在 iOS 取得系统内所有字型的名称: uses // 加入下面二个 uses 文件 iOSapi.UIKit, iOSapi.Foundatio ...

  3. Rest风格中关于JPA使用懒加载的坑

    公司最近使用的ORM框架是JPA实现产品使用的是hibernate,曾经看过一篇博客上面说的是如果团队里面没有一个精通hibernate的人,那么最好不要使用它,我现在是深刻的体会到了.但是使用什么框 ...

  4. 2016读书List

    2016年读书书单. 1. <华尔街漫步> + <战胜华尔街>+ <华尔街之狼> 2. <野蛮大陆> 3. <第三帝国的最后十四天> 4. ...

  5. PHP curl超时问题

    今天调试一个非常老的代码时  发现nginx服务器超时  改了下nginx配置 发现是后台脚本一直等待  排查到最后发现是curl 超时引起的等待 具体解决方案: curl_setopt( $this ...

  6. Mysql优化的几点总结

    正常情况下,初创公司的流量并不是很大,mysql数据库在未做优化的情况依然可以满足性能要求,特别是5.6版本后mysql在性能上还是有了很大提升,所以在初期并没有花精力在此上面.但后来发生的一系列问题 ...

  7. Alfresco 4 项目介绍

    body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; }       Alfresco 是一个开源的企业内容管理系统(ECM) ...

  8. TestNG官方文档中文版(3)-testng.xml

    TestNG的官方文档的中文翻译版第3章,原文请见 http://testng.org/doc/documentation-main.html 3 - testng.xml 调用TestNG由几种不同 ...

  9. easyui datagrid 分页略解

    easyui datagrid 本身自带了分页功能. 但是这个需要你自己控制. 在后台可以得到两个datagrid的参数,rows 和page.其中rows是每页要显示的个数,page是第几页.单纯的 ...

  10. WCF的三个名称/命名空间,你是否傻傻分不清楚?

    在定义和寄宿WCF服务的时候会面临三个名称/命名空间,它们分别是ServiceContractAttribute.ServiceBehaviorAttribute和Binding的Name和Names ...