Oracle 运维篇+修改表/索引的内存加载属性

标签:常驻内存、表keep、索引keep、把表/索引固定到内存、把表/索引加载到内存
优点:通过修改表的内存驻留方式,可以优化表的读取速度
易学:文中删去了不需要的多余部分,让初学者一目了然一学就会
温馨提示:如果您发现本文哪里写的有问题或者有更好的写法请留言或私信我进行修改优化


★ 知识点
※ buffer_pool(数据缓冲区)分为三部分:一部分是DEFAULT,一部分是KEEP池,一部分是RECYCLE池
※ 新版本推荐使用:db_cache_size、db_keep_cache_size、db_recycle_cache_size、
※ 版本参数变化
    ·buffer_pool_keep该参数在Oracle 8i中使用,并且在Oracle 9i中已弃用。此参数在10g中不可用
    ·buffer_pool_recycle该参数在Oracle 8i中使用,并且在Oracle 9i中已弃用。此参数在10g中不可用
※ 对象的buffer_pool和cache属性相互独立,可以分开设置也可以一起设置
    ·alter table/index xxx storage(buffer_pool default/keep/recycle)  cache/nocache
    ·alter table/index xxx storage(buffer_pool default/keep/recycle) 
    ·alter table/index xxx cache/nocache
※ 您无法指定CACHE索引组织的表。但是,索引组织的表隐式提供了CACHE行为。


★ 修改数据库内存参数
show parameter db_keep_cache_size
alter system set db_keep_cache_size = 8G scope=both;    
select m.COMPONENT,round(m.CURRENT_SIZE/1024/1024) mb from v$memory_dynamic_components m;
 

★ 修改表/索引的内存驻留属性

命令案例

LRU端

原理

alter table/index xxx storage(buffer_pool keep) cache

MRU

keep时一律先进先出

alter table/index xxx storage(buffer_pool keep) nocache

MRU

keep时一律先进先出

alter table/index xxx storage(buffer_pool recycle) cache

MRU

recycle时可以控制冷热

alter table/index xxx storage(buffer_pool recycle)nocache

LRU

recycle时可以控制冷热

alter table/index xxx storage(buffer_pool default) cache

MRU

default时可以控制冷热

alter table/index xxx storage(buffer_pool default) nocache

LRU

default时可以控制冷热

★ 手动加载(全表并行扫描、索引快速扫描)
select /*+ full(e) parallel(8) */ count(*) from scott.emp e;
select /*+ index_ffs(e pk_emp) */ count(*) from scott.emp e;

★ 查询内存设置
※ 查看dba_tables(不代表实际已经加载)
select t.owner,t.table_name,t.buffer_pool,t.cache from dba_tables t where table_name='EMP';
※ 查看v$db_object_cache(不推荐该视图,因为该表记录的是SHARED_POOL中记录过的内容,所以不准确)
select c.OWNER,c.NAME,c.TYPE from v$db_object_cache c where c.OWNER='SCOTT' order by c.TYPE,c.name;
※ 查看物理读情况(推荐,如果改完参数且物理读为0代表已经在内存中)
set autotrace on
select /*+ full(e) *//*+ no_result_cache */ count(*) from scott.emp e;
set autotrace off
※ 查看x$BH/v$BH视图(准确,但是较为复杂)(上下块数之差不应太多)

--指定表/索引在内存中的块数
select o.owner, o.object_name, o.object_id, count(*) bh_bloks
  from x$bh b, dba_objects o
 where b.OBJ = o.data_object_id
   and o.owner = 'SCOTT'
   and o.object_name = 'EMP'
 group by o.object_id, o.owner, o.object_name
union all
--指定表/索引在库中对象的实际块数
select e.owner, e.segment_name, o.object_id, sum(e.blocks)
  from dba_extents e, dba_objects o
 where e.owner = 'SCOTT'
   and e.segment_name = 'EMP'
   and e.owner = o.owner
   and e.segment_name = o.object_name
   and e.segment_type = o.object_type
 group by e.owner, e.segment_name, o.object_id;

※ 如果您觉得文章写的还不错, 别忘了在文末给作者点个赞哦 ~

over

猜你喜欢

转载自blog.csdn.net/zzt_2009/article/details/112395084