【問題記錄】ORA-04031 – shared_pool out of memory

ERROR:

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







 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章