文檔課題:alter system flush shared_pool指令解析.
資料庫:oracle 11.2.0.4 64位
場景描述:
作為DBA,一定遇到過ORA-04031共享池不夠用的情況,該告警主要展現在用戶端連接配接異常以及系統響應緩慢等問題上.
解決方案:
可先使用alter system flush shared_pool重新整理sga,該語句不會删除procedure與function,隻是暫時解決shared_pool中的碎片問題,大量不能共享的sql很快又會産生碎片.根本的解決辦法是優化sql,keep經常使用的包、cursor_sharing參數.注意該指令會造成短時間的性能下降,因為parse過的sql都被清理出sga.
測試過程:
查share_pool碎片.
SQL> select count(*) from x$ksmsp;
COUNT(*)
----------
14672
使用此前未曾使用過的查詢,讓share pool配置設定記憶體,增加share pool的chunk碎片.
SQL> select * from scott.emp t where empno in (select t.empno from scott.emp t where t.deptno in (20,30));
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
7566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
7900 JAMES CLERK 7698 1981-12-03 00:00:00 950 30
7902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
11 rows selected.
再次查share_pool碎片.
SQL> select count(*) from x$ksmsp;
COUNT(*)
----------
15069
說明:每個buckets碎片數量>2000就視作不太好的情況,可能會引起share pool latch争用.
SQL> alter system flush shared_pool;
System altered.
SQL> select count(*) from x$ksmsp;
COUNT(*)
----------
5185
總結:執行該指令是将緩存在library cache和data dictionary cache中的sql、pl/sql和資料字典定義都從共享池中清除,在負載很高的生産庫慎用該指令.
參考網址:
http://blog.itpub.net/29144194/viewspace-1219756/
https://blog.csdn.net/kadwf123/article/details/8564869
說明:以上内容基本來自以上網址,如有侵權,請聯系部落客删帖.