天天看點

如何将oracle 對象pin在共享池中

dbms_shared_pool.keep 可以将對象pin入shared_pool,而不進入lru 機制被keep的對象可以是資料庫對象,也可以是sql

dbms_shared_pool.unkeep為反操作。

實驗如下:(實驗環境 11.2.0.1)

執行一個sql,并檢視其在shared_pool 中的address和hash_value值。

  count(*)

----------

        29

address          hash_value  sql_text

---------------- ----------- ------------

00000001736c9e48 1083615814  select count(*) from yang_a

address          hash_value executions parse_calls

---------------- ---------- ---------- -----------

00000001736c9e48 1083615814          1           1

keep該sql語句的執行計劃到shared_pool。

pl/sql procedure successfully completed.

在v$db_object_cache 中查詢kept字段為yes ,說明該對象已經被儲存!

owner      name                                     kep

---------- ---------------------------------------- ---

           select count(*) from yang_a              yes

         1

因為已經被儲存了,是以執行删除hash_value值為1083615814 時候報錯,

begin sys.dbms_shared_pool.purge('00000001736c9e48,1083615814','c'); end;

*

error at line 1:

ora-06596: object cannot be  purged, object is permanently kept in shared pool

ora-06512: at "sys.dbms_shared_pool", line 31

ora-06512: at "sys.dbms_shared_pool", line 77

ora-06512: at line 1

對hash_value值為1083615814 執行計劃進行unkeep

再次删除

no rows selected

示範 keep對于隊列的作用。

建立隊列,預設為隊列在記憶體中的cache 為20.

sequence created.

   nextval

清除cache在記憶體中的隊列的值。

system altered.

        21

nextval為21 表示,随着flush 共享池,sequence的cache被清空了。

将隊列keep在緩存中,

        22

然後再次flush 共享池。

檢視nextval的值,結果:

        23

說明keep起作用了!被keep在共享池中的對象不會被flush 操作清除。

        24

        41

相信到這裡,我們可以對dbms_shared_pool.keep /unkeep 的作用有了初步的了解。^ _ ^