ORACLE 11GR2 新特性CACHE表與以前的區別

wzhalal發表於2014-06-27

alter system set db_keep_cache_size=80M --設定keep值大小
        alter table TBL_AIRCOMPANY storage(buffer_pool keep)--把表TBL_AIRCOMPANY設定成keep在pool池中
        ALTER TABLE TBL_AIRCOMPANY cache --讓TBL_AIRCOMPANY可以快取
       
        SELECT OBJECT_NAME, A.STATUS, COUNT(*)
 FROM V$BH A, USER_OBJECTS B
 WHERE A.OBJD = B.OBJECT_ID
 --AND OBJECT_NAME IN ('TBL_AIRCOMPANY')
 GROUP BY OBJECT_NAME, A.STATUS; --檢視是否在快取keep中
 
 


  --各個buffer的空間資訊

  select p.name,sum(a.cnum_repl) "total buffers",sum(a.anum_repl) "free buffers" from x$kcbwds a, v$buffer_pool p
    where a.set_id>=p.LO_SETID and
           a.set_id<=p.HI_SETID
    group by p.name;

--指令碼用來定位哪些object在buffer cache中存在,佔用的buffer cache的量是多少以及佔用的是什麼型別的buffer cache。

select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',

         4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',

         7,'16K SUBCACHE',8,'32KSUBCACHE','UNKNOWN') subcache,

         bh.object_name,bh.blocks

from x$kcbwds ds,x$kcbwbpd pd,(select set_ds,

         o.name object_name,count(*) BLOCKS

         from obj$ o, x$bh x where o.dataobj# = x.obj

         and x.state !=0 and o.owner# !=0

         group by set_ds,o.name) bh

where ds.set_id >= pd.bp_lo_sid

and ds.set_id <= pd.bp_hi_sid

and pd.bp_size != 0

and ds.addr=bh.set_ds
order by  decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',

         4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',

         7,'16K SUBCACHE',8,'32KSUBCACHE','UNKNOWN'),bh.blocks;


 

select
(select value from V$SYSSTAT where name='physical write total bytes')/
(select value from V$SYSSTAT where name='physical read total bytes')*100||'%' 寫讀比例
from dual


一、對於普通表的cache方法:
SQL> conn test/test 已連線。
SQL> alter table t1 storage (buffer_pool keep) cache;
表已更改。
查詢普通表是否已經被cache:
  SQL> select table_name,cache,buffer_pool from user_TABLES;
TABLE_NAME                     CACHE      BUFFER_
------------------------------ ---------- -------
T1                                 Y      KEEP
 
 

二、對於普通LOB型別的segment的cache方法
SQL> desc t2
名稱 是否為空? 型別
---------------------------------------- -------- ----------------------------
ID NUMBER
C2 CLOB
SQL> alter table t2 modify lob(c2) (storage (buffer_pool keep) cache);
表已更改。
 

三、對基於CLOB型別的物件的cache方法
 
SQL> desc lob1
名稱 是否為空? 型別
----------------------------------------- -------- --------------- ID NUMBER
C1 XMLTYPE
SQL> alter table lob1 modify lob(c1.xmldata) (storage (buffer_pool keep) cache);
表已更改。

那麼,怎麼測試lob segment是否被cache了呢?

來看看oracle給我的回覆:

Hi Frank,

To verify which buffer pool is used by a lob segment query dba_segments,

See below test case

SQL> create table test(name varchar2(10), address clob);

Table created.

SQL> select table_name,cache,buffer_pool from user_TABLES;

TABLE_NAME CACHE BUFFER_
------------------------------ ----- -------
TEST N DEFAULT


SQL> alter table test modify lob(address) (storage (buffer_pool keep) nocache);

Table altered.

SQL> select table_name,cache,buffer_pool from user_TABLES;

TABLE_NAME CACHE BUFFER_
------------------------------ ----- -------
TEST N DEFAULT

SQL> select segment_name,segment_type,buffer_pool from user_segments;

SEGMENT_NAME
--------------------------------------------------------------------------------
SEGMENT_TYPE BUFFER_
------------------ -------
TEST
TABLE DEFAULT

SYS_IL0000123006C00002$$
LOBINDEX KEEP

SYS_LOB0000123006C00002$$
LOBSEGMENT KEEP


SQL> select column_name,segment_name from user_lobs;

COLUMN_NAME
--------------------------------------------------------------------------------
SEGMENT_NAME
------------------------------
ADDRESS
SYS_LOB0000123006C00002$$


SQL>

Thus you can see the lob segment SYS_LOB0000123006C00002$$ is mapped to clob column ad
dress and is using
keep buffer pool as expected.

User_objects will display results for object as a whole not for individual columns.

See below, we need to alter the complete table to use keep buffer_pool and user_tables will then
display results as expected.

SQL> alter table test storage (buffer_pool keep);

Table altered.

SQL> select table_name,cache,buffer_pool from user_TABLES;

TABLE_NAME CACHE BUFFER_
------------------------------ ----- -------
TEST N KEEP

SQL>


 

 

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

相關文章