alter system flush shared_pool的作用 .
alter?system?flush?shared_pool的作用
The FLUSH SHARED POOL clause lets you clear all data from the shared pool in the system global area (SGA). The shared pool stores Cached data dictionary information and Shared SQL and PL/SQL areas for SQL statements, stored procedures, function, packages, and triggers.
This statement does not clear shared SQL and PL/SQL areas for items that are currently being executed. You can use this clause regardless of whether your instance has the database dismounted or mounted, open or closed.
實驗步驟如下:
----------------------------------------------------------------------------------------
1.查看shared_pool中碎片
SQL> select count(*) from x$ksmsp;
COUNT(*)
----------
?????7260
2.使用一個以前未曾使用過的查詢,來讓share pool分配內存,增加share pool中的chunk碎片
SQL> select count(*) from user_tables;
COUNT(*)
----------
??????667
3.再次查詢shared_pool中的碎片
SQL> select count(*) from x$ksmsp;
COUNT(*)
----------
?????7515
每個buckets的碎片數量>2000就認為是不太好的一個情況,可能會引起share pool latch爭用!
4.使用alter system flush shared_pool命令,并再次查詢shared_pool中的碎片
SQL> alter system flush shared_pool;
系統已更改。
SQL> select count(*) from x$ksmsp;
COUNT(*)
----------
?????7194
-----------------------------------------------------------------------------------------------------------------------
總結:執行這個語句的結果是將緩存在library cache和data dictionary cache 中的sql,pl/sql和數據字典定義都從共享池中清除了
在負載很重的生產庫里執行flush shared_pool無異于自殺...慎用!
?
注釋######################################################################
X$KSMSP的名稱含義為:
[K]ernal [S]torage [M]emory Management [S]GA Hea[P]
其中每一行都代表著shared pool中的一個chunk
我們看一下x$ksmsp的結構:
?
| SQL> desc x$ksmsp Name Null? Type --------- -------- ---------------- ADDR RAW(4) INDX NUMBER INST_ID NUMBER KSMCHIDX NUMBER KSMCHDUR NUMBER KSMCHCOM VARCHAR2(16) KSMCHPTR RAW(4) KSMCHSIZ NUMBER KSMCHCLS VARCHAR2(8) KSMCHTYP NUMBER KSMCHPAR RAW(4) |
?
我們關注以下幾個字段:
KSMCHCOM是注釋字段,每個內存塊被分配以后,注釋會添加在該字段中.
x$ksmsp.ksmchsiz代表塊大小
x$ksmsp.ksmchcls列代表類型,主要有四類,說明如下:
free
Free chunks--不包含任何對象的chunk,可以不受限制的被分配.
recr
Recreatable chunks--包含可以被臨時移出內存的對象,在需要的時候,這個對象可以
被重新創建.例如,許多存儲共享sql代碼的內存都是可以重建的.
freeabl
Freeable chunks--包含session周期或調用的對象,隨后可以被釋放.這部分內存有時候
可以全部或部分提前釋放.但是注意,由于某些對象是中間過程產生的,這些對象不能
臨時被移出內存(因為不可重建).
perm
Permanent memory chunks--包含永久對象.通常不能獨立釋放.
我們可以通過查詢x$ksmsp視圖來考察shared pool中存在的內存片的數量
不過注意:Oracle的某些版本(如:10.1.0.2)在某些平臺上(如:HP-UX PA-RISC 64-bit)查
詢該視圖可能導致過度的CPU耗用,這是由于bug引起的.
總結
以上是生活随笔為你收集整理的alter system flush shared_pool的作用 .的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle Parallel Exec
- 下一篇: 五分钟精通Oracle Hints