Oracle Buffer Cache优化思路


最近看了几页书,做个笔记,拷贝Oracle官方文档上的一段话,当然Buffer Cache远不止这些,只是看英文的确速度好慢的,我现在最想说的一句话是:我需要更多的时间。最近杂事太多,没多少自己能够支配的时间。什么时候我能够非常流利的看英文呢?step by step 了,太多细节的东西只能从官方文档上获知,的确是个金库的东西,自己却拿不出金子来,step by step !
Database Buffer Cache
The database buffer cache is the portion of the SGA that holds copies of data blocks read from datafiles. All user processes concurrently connected to the instance share access to the database buffer cache.database buffer cache是sga的一部分,用于保持从数据文件读取数据块的副本。所有用户进程共同访问database buffer cache。
数据库的读写操作应尽量在内存中完成,减少IO次数是数据库性能优化的基本策略。

优化buffer cache的思路:

1)根据经验设置db_cache_size参数,例如,db_cache_size=SGA_TARGET*80%。
2)分析AWR报告中的Buffer Hit值(Instance Efficiency Percentages (Target 100%) )。

      
   需要关注的等待事件(如果这些等待事件出现在Top-5中,则说明Buffer Cache工作效率不高):
       Latch:cache buffer chains
       Latch:cache buffer LRU chains
       Buffer busy waits
       Read waits
       Free buffer waits

Latch:cache buffer chains与Latch:cache buffer LRU chains
表示数据库中存在一些数据块被频繁读取,即所谓的热块数据。如,www.bkjia.com频繁读取的代码表(?),UNDO头数据(?)、单调增长的索引等。
以下可以查询热块数据:
select * from (select owner,object_name,object_type,statistic_name,sum(value)
                from v$segment_statistics
               group by owner,object_name,object_type,statistic_name
               order by sum(value) desc)
where rownum<10;
优化方法:如,减少代码数据的读取次数,使用reverse key索引,以及10g的Global Hash-patition分区索引等。

Buffer busy waits
表示多个应用在并发访问某个Buffer Cache数据块时出现等待事件。这种数据块可能是应用表或索引,也可能是UNDO(?)、Segment Header(?)等系统数据。
以下可以查询等待事件涉及的对象:
select object_name,statistic_name,value 
  from v$segment_statistics 
 where statistic_name ='buffer busy waits' and value > 2000;
优化方法:如,分析是否有全表扫描,索引是否太多,索引单调增长等,归根到底还是分析应用。

Read waits
包括:db file sequential read、db file parallel read、db file scattered read。一般而言,只要db file scattered read不是最主要的等待事件,或者所占比例不高,上述事件即使出现在Top-5等待事件中也是正常现象。
如果这些等待事件非常高,或者所占比例很高。优化方法:1,同样地,首先优化应用,如是否有太多的全表扫描,索引碎片是否严重。2.适当扩大db_cache_size。3.分析磁盘I/O效率。

Free buffer waits
表示将Buffer Cache 内容写到磁盘的速度,赶不上其它应用申请空闲Buffer Cache的要求。优化方法:同样地,首先优化应用,如是否有太多的全表扫描,索引效率是否比较高。2.适当扩大db_cache_size。3.扩大db_writer_processes参数,增加DBWn进程数量,加快将Buffer Cache内容写到磁盘的速度。
db_writer_processes默认为1或cpu_count/8,默认值通常就可以,如果需要设置db_writer_processes,请不要超过cpu_count,以避免cpu资源无谓消耗。

其它优化方法,将表设计成cache表,等等。
总地来说,首要任务还是优化应用!

oracle10gR2中关于段级别的统计信息(Segment-Level Statistics)
获取段级别的统计信息能够帮助我们识别与个别段相关的性能问题,收集和查看它们能够更快的识别热表与索引。在查看wait events与system statistics识别出性能问题之后,可以使用segment-level statistics找到导致性能问题的表或索引。如:V$SYSTEM_EVENT暗示出buffer busy waits导致了一定数量的等待时间,这时候你可以查询V$SEGMENT_STATISTICS来获取导致buffer busy waits的top segments。因此你可以将焦点移动到这些segments来消除发现的性能问题。
与段级别的统计信息相关的动态性能视图:
1.V$SEGSTAT_NAME This view lists the segment statistics being collected, as well as the properties of each statistic (for instance, if it is a sampled statistic).(收集的段统计信息,含有一个标识是否为采样统计信息的属性)
2.V$SEGSTAT This is a highly efficient, real-time monitoring view that shows the statistic value, statistic name, and other basic information.(高效率实时监控视图,显示统计信息值,统计名称和其它基本信息)
3.V$SEGMENT_STATISTICS This is a user-friendly view of statistic values. In addition to all the columns of V$SEGSTAT, it has information about such things as the segment owner and table space name. It makes the statistics easy to understand, but it is more costly.(显示更友好的统计信息值的视图,不仅包含V$SEGSTAT的所有字段,还提供了段所有者和表空间名称.这使得查询统计信息更加容易,但代价也同样的更高。)

相关内容