ORA-04031: unable toallocate 28064 bytes of shared memory ("shared
pool","unknownobject","sga heap(1,0)","session param values")
看下引发该错的具体原因:
[/home/oracle]$oerr ora 4031
04031,00000, "unable to allocate %s bytes of shared memory(\"%s\",\"%s\",\"%s\",\"%s\")"
//*Cause: More shared memory is neededthan was allocated in the shared
// pool.
//*Action: If the shared pool is out of memory, either use the
// dbms_shared_pool package to pin largepackages,
// reduce your use of shared memory, orincrease the amount of
// available shared memory by increasingthe 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. 没有绑定编量造成shared_pool碎片过多,同时shared_pool_size太小
(1)这个情况是比较常见的。
(2)第二种情况通常会建议使用绑定变量,或者用简单的加大shared_pool,临时的解决方法就是alter system flush shared_pool。
2. Large_pool,Java_pool太小造成的
(1)这个通过错误信息的提示很容易判断(Ora-04031 cannot allocate .. memeory in [large_pool])
(2)解决方法就是简单的加大 Large_pool or Java_pool
3. 过度的开CURSOR而不关闭。
目前,此问题发生的越来越多,特别是在JAVA的运行环境中,屡见不鲜。加大Shared_pool或者flush shared_pool往往只能延迟问题出现的时间,而无法避免此问题。
判断方法:
select count(*) from v$open_cursor ;
select *from v$sysstat
where name ='opened cursors current';
假如出来的值特大(以万为单位)时,基本就可以确定是这个原因了。
解决这个问题的方法就是检查程序,看是否没有正常的关闭cursor(对于JAVA来说,就是没有关闭Statement)。或者select sql_text from v$open_cursor,看看都是哪些cursor没关闭,再去检查车程序。
也有的程序使用了保持一定量的cursor一直open,从而避免cursor过多次的开启,来提高性能。对于这种情况,则应该选择适当的shared_pool_size和控制keep_opening的cursor的量。
另外,Oracle参数session_cached_cursors也有可能过大,解决的方法就是把它降低到适当的值。
由于我的shared_pool out of memory,导致数据库也连接不上。
[/home/oracle]$sqlplus '/ as sysdba'
SQL*Plus:Release 9.2.0.8.0 - Production on Wed Nov 20 09:23:18 2013
Copyright(c) 1982, 2002, Oracle Corporation. Allrights reserved.
Connected.
SQL>select name from v$database;
selectname from v$database
*
ERROR atline 1:
ORA-01012: not logged on
因此先杀掉一些no local的进程:
[/home/oracle]$ps -ef|grep ora
oracle 479366 1 0 Sep 21 - 3:10 ora_qmn0_wciqhist
oracle 524520 1 0 Sep 21 - 0:01 ora_reco_wciqhist
oracle 565304 1 0 Sep 21 - 1:15 ora_smon_wciqhist
oracle 602266 7110904 3 09:24:50 pts/0 0:00 ps -ef
oracle 622714 1 0 Sep 21 - 267:24ora_p003_wciqhist
oracle 663618 1 0 Oct 29 - 13:23 oraclewciqhist (LOCAL=NO)
oracle 676056 1 0 Sep 21 - 68:46ora_dbw0_wciqhist
oracle 3285056 1 0 Sep 21 - 5054:33 ora_p004_wciqhist
oracle 7032872 1 0 Sep 21 - 66:01 ora_p001_wciqhist
oracle 7057466 7110904 0 09:24:50 pts/0 0:00 grep ora
oracle 7082092 1 0 Sep 21 - 10:21 ora_ckpt_wciqhist
oracle 7094466 1 0 Sep 21 - 75:41 ora_p002_wciqhist
oracle 7102570 1 0 Sep 21 - 59:15 ora_lgwr_wciqhist
oracle 7110904 7041124 1 09:23:08 pts/0 0:00 -ksh
oracle 7118988 1 0 Oct 29 - 10:57 oraclewciqhist (LOCAL=NO)
oracle 7123066 1 0 Sep 23 - 0:00 /u01/oracle/product/9.2.0/bin/tnslsnr LISTENER_WCIQHIST -inherit
oracle 7127224 1 0 Nov 14 - 0:00 oraclewciqhist (LOCAL=NO)
oracle 7139538 7254076 0 09:15:14 pts/0 0:00 -ksh
oracle 7159872 1 0 Sep 21 - 56:26 ora_dbw1_wciqhist
oracle 7163922 1 8 Sep 21 - 5472:38 ora_p000_wciqhist
oracle 7168048 1 0 Nov 18 - 0:01 oraclewciqhist (LOCAL=NO)
oracle 7188534 1 0 Sep 21 - 4:30 ora_pmon_wciqhist
oracle 7192688 1 0 Nov 14 - 0:56 oraclewciqhist (LOCAL=NO)
oracle 7200996 1 0 Sep 21 - 0:50 ora_arc1_wciqhist
oracle 7209026 1 0 Nov 14 - 2:17 oraclewciqhist (LOCAL=NO)
oracle 7213190 1 0 Nov 06 - 0:17 oraclewciqhist (LOCAL=NO)
oracle 7237842 1 0 Sep 21 - 28:38 ora_lsp0_wciqhist
oracle 7241860 1 0 Sep 21 - 5:43 ora_arc0_wciqhist
[/home/oracle]$kill -9 7118988 7168048 7192688 72090267213190
然后就可以连上了
Connectedto:
Oracle9iEnterprise Edition Release 9.2.0.8.0 - 64bit Production
With thePartitioning option
JServerRelease 9.2.0.8.0 - Production
对于4031错误,我的解决方法:
因为该库的启停不影响应用,于是直接重启了该库。
注意:由于该库是logical standby,在停库前要先停日志应用,同样在启动数据库后再打开日志应用:
alterdatabase stop logical standby apply;
shutdownimmediate;
startup;
alterdatabase start logical standby apply;
参考:http://bbs.csdn.net/topics/250081959