由于业务需要,生产Oracle 10.2.0.2 RAC环境的数据库需要调整db_cache_size,从原来的4G调整至7G。没想到在调整后,却引发了ORA-4031错误。
Thu Oct 13 08:25:05 2011
Errors in file /oracle/oracle/admin/UC/udump/u1_ora_13757.trc:
ORA-00603: ORACLE server session terminated by fatal error
ORA-00604: error occurred at recursive SQL level 1
ORA-04031: unable to allocate 1048 bytes of shared memory ("shared pool","select name,online$,contents...","Typecheck","kgghteInit")
ORA-00604: error occurred at recursive SQL level 1
ORA-04031: unable to allocate 1048 bytes of shared memory ("shared pool","select name,online$,contents...","Typecheck","seg:kggfaAllocSeg")
Thu Oct 13 08:25:05 2011
Errors in file /oracle/oracle/admin/UC/udump/u1_ora_1444.trc:
ORA-00603: ORACLE server session terminated by fatal error
ORA-00604: error occurred at recursive SQL level 1
ORA-04031: unable to allocate 4120 bytes of shared memory ("shared pool","select name,online$,contents...","Typecheck","kgghtInit")
ORA-00604: error occurred at recursive SQL level 1
ORA-04031: unable to allocate 4120 bytes of shared memory ("shared pool","select name,online$,contents...","Typecheck","kgghtInit")
从当时的等待事件来看,主要的有:
|
library cache lock |
|
cursor: pin S wait on X |
|
row cache lock |
报错导致了生产的应用中断,最后在调大了shared_pool_size后,问题才得以解决。
事后检查了v$sgastat,发现gcs resources 和gcs shadows 组件较之前占用了更多的shared pool。(由120M上升至230M左右)
|
shared pool |
gcs resources |
150351024 |
|
shared pool |
sql area |
129428640 |
|
shared pool |
gcs shadows |
94714752 |
|
shared pool |
free memory |
58228912 |
这里,gcs resources和gcs shadows是被用来处理RAC中的buffer cahces的,所以其内存使用情况由buffer cache的大小决定,由于这次调整了db_cache_size,导致了这2部分组件需要占用更多的shared pool内存,而shared pool没有及时调整大小(这套系统sga_target=0,手工管理sga各组件),最终导致了共享池中关键的资源被换出,引发数据库ORA-4031错误。
Oracle推荐在RAC环境中设置较大的shared_pool_size初始化参数,此外显示地设置较大的GCS和GES资源结构的初始化分配数(INITIAL_ALLOCATION)也有利于避免ORA-4031。
估算和监控gcs resources和gcs shadows,我们可以使用v$resource_limit视图。这里估算的公式为:
gcs_resources = initial_allocation * 120 bytes
gcs_shadows = initial_allocation * 72 bytes
此公式是在Solaris-64bit Oracle 10gR1上的最小值,不同的OS和DB版本可能导致这个估算值有所不同。另外,由于内存分配的复杂机制,实际值可能比此估算值大很多。
就本次这套系统:
gcs_resources(估算)= 976083 * 120 bytes = 117129960 bytes < gcs_resources(实际)=150351024 bytes
gcs_shadows(估算)= 976083 * 72 bytes = 70277976 bytes < gcs_shadows(实际)= 94714752 bytes
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/20750200/viewspace-709201/ ,如需转载,请注明出处,否则将追究法律责任。