ORA-04031錯誤分析

xinxinhg發表於2004-11-10
http://blog.itpub.net/post/11/4616 本文作者:husthxd [@more@]

本文作者:husthxd

ORACLE Bug導致的ORA-04031:

BUG

Description

Workaround

Fixed

<>

ORA-4031 / SGA memory leak of PERMANENT memory occurs for buffer handles.

_db_handles_cached = 0

8172, 901

<>

ORA-4031 due to leak / cache buffer chain contention from AND-EQUAL access 

Not available

8171, 901

 Bug:1318267  
   Not Public

INSERT AS SELECT statements may not be shared when they should be if  TIMED_STATISTICS. It can lead to ORA-4031

_SQLEXEC_PROGRESSION_COST=0 

8171,  8200

  Bug:1193003
     Not Public

Cursors may not be shared in 8.1 when they should be

Not available

8162, 8170, 901

<>

ORA-4031/excessive "miscellaneous"
shared pool usage possible.
(many PINS)

None-> This is known to affect the XML parser.

8174, 9013, 9201

<>

Several number of BUGs related
to ORA-4031 erros were fixed
in the 9.2.0.5 patchset

 

9205

 
2.編譯java程式碼時出現ORA-4031錯誤


出現ORA-04031: unable to allocate bytes of shared memory ("shared pool","unknown object","joxlod: init h", "JOX: ioc_allocate_pal")增大JAVA_POOL_SIZE到一個合適的值即可(一般100m足夠)。

3.LARGE_POOL_SIZE過小導致ORA-04031: unable to allocate XXXX bytes of shared memory ("large pool","unknown object","session heap","frame"),增大LARGE_POOL_SIZE即可。

4.ORA-04031錯誤的高階分析


SESSION級:

SQL> alter session set events '4031 trace name errorstack level 3';
SQL> alter session set events '4031 trace name HEAPDUMP level 3';


INSTANCE級:


初始化引數中設定


event = "4031 trace name errorstack level 3"
event = "4031 trace name HEAPDUMP level 3"

5.調整SHARED_POOL_SIZE以避免ORA-04031錯誤。


1)使用DBMS_SHARED_POOL.KEEP把經常執行的package keep到共享池中。

2)調整引數SHARED_POOL_RESERVED_SIZE大致為SHARED_POOL_SIZE的10%;但如果SHARED_POOL_SIZE很大的話可以適當調小該引數;如果     SHARED_POOL_RESERVED_MIN_ALLOC低於default值的話,適當調大該引數,因為SHARED_POOL_RESERVED_MIN_ALLOC較低會導致更多共享語句從SHARED_POOL_RESERVED_SIZE所指定的區域中分配記憶體。

3)一些用於定位問題的指令碼

     A.定位應該使用繫結變數的sql語句
    
     SELECT substr(sql_text,1,40) "SQL",
     count(*) ,
     sum(executions) "TotExecs"
     FROM v$sqlarea
     WHERE executions < 5
     GROUP BY substr(sql_text,1,40)
     HAVING count(*) > 30
     ORDER BY 2
     /
    
     40表示sql語句的前40個字元是一樣的,5表示執行次數小於5次,30表示在shared_pool_size中出現不下30次。
    
     B.以sys使用者執行以下語句
    
     SELECT * FROM X$KSMLRU WHERE ksmlrsiz > 0
     /
    
     X$KSMLRU 表顯示那段記憶體的分配導致大多數的chunks從共享記憶體中aged out。
    
     C.獲得library cache hit
     SELECT SUM(PINS) "EXECUTIONS",
                 SUM(RELOADS) "CACHE MISSES WHILE EXECUTING"
                 FROM V$LIBRARYCACHE
     /
    
     D.顯示在free list中可用的chunks
     select '0 (<140)' BUCKET, KSMCHCLS, 10*trunc(KSMCHSIZ/10) "From",
     count(*) "Count" , max(KSMCHSIZ) "Biggest",
     trunc(avg(KSMCHSIZ)) "AvgSize", trunc(sum(KSMCHSIZ)) "Total"
     from x$ksmsp
     where KSMCHSIZ<140
     and KSMCHCLS='free'
     group by KSMCHCLS, 10*trunc(KSMCHSIZ/10)
     UNION ALL
     select '1 (140-267)' BUCKET, KSMCHCLS, 20*trunc(KSMCHSIZ/20) ,
     count(*) , max(KSMCHSIZ) ,
     trunc(avg(KSMCHSIZ)) "AvgSize", trunc(sum(KSMCHSIZ)) "Total"
     from x$ksmsp
     where KSMCHSIZ between 140 and 267
     and KSMCHCLS='free'
     group by KSMCHCLS, 20*trunc(KSMCHSIZ/20)
     UNION ALL
     select '2 (268-523)' BUCKET, KSMCHCLS, 50*trunc(KSMCHSIZ/50) ,
     count(*) , max(KSMCHSIZ) ,
     trunc(avg(KSMCHSIZ)) "AvgSize", trunc(sum(KSMCHSIZ)) "Total"
     from x$ksmsp
     where KSMCHSIZ between 268 and 523
     and KSMCHCLS='free'
     group by KSMCHCLS, 50*trunc(KSMCHSIZ/50)
     UNION ALL
     select '3-5 (524-4107)' BUCKET, KSMCHCLS, 500*trunc(KSMCHSIZ/500) ,
     count(*) , max(KSMCHSIZ) ,
     trunc(avg(KSMCHSIZ)) "AvgSize", trunc(sum(KSMCHSIZ)) "Total"
     from x$ksmsp
     where KSMCHSIZ between 524 and 4107
     and KSMCHCLS='free'
     group by KSMCHCLS, 500*trunc(KSMCHSIZ/500)
     UNION ALL
     select '6+ (4108+)' BUCKET, KSMCHCLS, 1000*trunc(KSMCHSIZ/1000) ,
     count(*) , max(KSMCHSIZ) ,
     trunc(avg(KSMCHSIZ)) "AvgSize", trunc(sum(KSMCHSIZ)) "Total"
     from x$ksmsp
     where KSMCHSIZ >= 4108
     and KSMCHCLS='free'
     group by KSMCHCLS, 1000*trunc(KSMCHSIZ/1000)
     /
      
     E.檢查高版本計數的sql語句
     SELECT address, hash_value,
                         version_count ,
                         users_opening ,
                         users_executing,
                         substr(sql_text,1,40) "SQL"
                   FROM v$sqlarea
                  WHERE version_count > 10
     /
    
    
     F.檢查使用了多量的shared memory的sql語句

     SELECT substr(sql_text,1,40) "Stmt", count(*),
                         sum(sharable_mem)    "Mem",
                         sum(users_opening)   "Open",
                         sum(executions)      "Exec"
                   FROM v$sql
                  GROUP BY substr(sql_text,1,40)
                 HAVING sum(sharable_mem) > memsize
     / 
    

參考文件:


【metalink 】Diagnosing and Resolving Error ORA-04031

【metalink 】Understanding and Tuning the Shared Pool

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/166555/viewspace-780341/,如需轉載,請註明出處,否則將追究法律責任。

相關文章