5 Copyright © Oracle Corporation, 2002. All rights reserved. Sizing the Buffer Cache 5-2 Copyright © Oracle Corporation, 2002. All rights reserved. Objectives After completing this lesson, you should be able to do the following: • Employ the buffer cache sizing advisor • Describe how the buffer cache is used by different Oracle processes • Create and manage different buffer caches • Monitor the use of the buffer caches • Identify and resolve buffer cache performance problems 5-3 Copyright © Oracle Corporation, 2002. All rights reserved. Overview Data files SGA DB buffer cache Checkpoint Queue . . . . LRU lists DBWn Server DB_BLOCK_SIZE DB_CACHE_SIZE DB_KEEP_CACHE_SIZE DB_RECYCLE_CACHE_SIZE DB_BLOCK_CHECKSUM . . . . 5-5 Copyright © Oracle Corporation, 2002. All rights reserved. Buffer Cache Sizing Parameters • The buffer cache can consist of independent subcaches for buffer pools and for multiple block sizes. • The DB_BLOCK_SIZE parameter determines the primary block size, which is the block size used for the system tablespace and the primary buffer caches (recycle, keep, and default). • The following parameters define the sizes of the caches for buffers for the primary block size: – DB_CACHE_SIZE – DB_KEEP_CACHE_SIZE – DB_RECYCLE_CACHE_SIZE 5-6 Copyright © Oracle Corporation, 2002. All rights reserved. Dynamic Buffer Cache Advisory Parameter • The buffer cache advisory feature enables and disables statistics gathering for predicting behavior with different cache sizes. • DBAs can use the information provided by these statistics to size the buffer cache optimally for a given workload. • The buffer cache advisory is enabled by means of the DB_CACHE_ADVICE initialization parameter: – This parameter is dynamic and can be changed using ALTER SYSTEM. – Three values are allowed: Off, On, and Ready. 5-7 Copyright © Oracle Corporation, 2002. All rights reserved. View to Support Buffer Cache Advisory • Buffer cache advisory information is collected in the v$db_cache_advice view. • The view contains different rows that estimate the number of physical reads for different caches. • The rows also compute a physical read factor, which is the ratio of the number of estimated reads to the number of actual reads. 5-8 Copyright © Oracle Corporation, 2002. All rights reserved. Using the v$db_cache_advice View SQL> SELECT size_for_estimate "Cache Size (MB)", 2 buffers_for_estimate "Buffers", 3 estd_physical_read_factor AS 4 "Estd Phys Read Factor", 4 estd_physical_reads "Estd Phys Reads" 5 FROM v$db_cache_advice 6 WHERE name = 'DEFAULT' 7 AND block_size = ( 8 SELECT value 9 FROM v$parameter 10 WHERE name = 'db_block_size') 11 AND advice_status = 'ON'; 5-9 Copyright © Oracle Corporation, 2002. All rights reserved. Using the Buffer Cache Advisory 5-10 Copyright © Oracle Corporation, 2002. All rights reserved. SGA DB buffer cache Checkpoint Queue . . . . LRU lists . . . . Managing the Database Buffer Cache DBWn LGWR Data files 1 Server 2 2 3 4 5-11 Copyright © Oracle Corporation, 2002. All rights reserved. SGA DB buffer cache Checkpoint Queue . . . . . . . . Managing the Database Buffer Cache DBWn LGWR Server Data files LRU lists [...]... waits on the buffer cache • Diagnostic measures – Wait events – Cache hit ratio – The v$db _cache_ advice view • Tuning techniques: – Reduce the number of blocks required by SQL statements – Increase buffer cache size – Use multiple buffer pools – Cache tables – Bypass the cache for sorting and parallel reads 5-12 Copyright © Oracle Corporation, 2002 All rights reserved Diagnostic Tools v$sysstat v $buffer_ pool_statistics... v $buffer_ pool_statistics v $buffer_ pool v$db _cache_ advice SGA LRU list v$sesstat v$system_event v$session_wait Checkpoint queue Buffer cache v$bh v $cache Keep buffer pool Recycle buffer pool DB _CACHE_ SIZE DB_KEEP _CACHE_ SIZE DB_RECYCLE _CACHE_ SIZE 5-14 Copyright © Oracle Corporation, 2002 All rights reserved Statspack Report Performance Manager 5-16 Copyright © Oracle Corporation, 2002 All rights reserved Buffer Cache Performance... statements have been tuned • There is no undue page faulting • The previous increase of the buffer cache was effective • Low cache hit ratio 5-23 Copyright © Oracle Corporation, 2002 All rights reserved Using Multiple Buffer Pools SGA DB buffer caches Recycle pool Keep pool Default pool 5-25 Copyright © Oracle Corporation, 2002 All rights reserved Defining Multiple Buffer Pools In the Oracle database: •... name = 'free buffer inspected'; NAME VALUE - -free buffer inspected 183 5-17 Copyright © Oracle Corporation, 2002 All rights reserved More Buffer Cache Performance Indicators From v$system_event: SQL> SELECT event, total_waits 2 FROM v$system_event 3 WHERE event in 4 ('free buffer waits', 5 'buffer busy waits'); EVENT TOTAL_WAITS free buffer waits 337 buffer busy waits... database: • Individual pools have their own size defined by: – DB _CACHE_ SIZE – DB_KEEP _CACHE_ SIZE – DB_RECYCLE _CACHE_ SIZE • These parameters are dynamic • Latches are automatically allocated by Oracle RDBMS 5-26 Copyright © Oracle Corporation, 2002 All rights reserved Enabling Multiple Buffer Pools CREATE INDEX cust_idx … STORAGE (BUFFER_ POOL KEEP …); ALTER TABLE customer STORAGE (BUFFER_ POOL RECYCLE); ALTER... size is less than 10% of the default buffer pool size • Recycle pool – Blocks are not reused outside of transaction – Segment size is more than twice the default buffer pool size 5-34 Copyright © Oracle Corporation, 2002 All rights reserved Dictionary Views with Buffer Pool Information SQL> SELECT id, name, block_size, buffers 2 FROM v $buffer_ pool; ID -1 2 3 5-35 NAME block_size BUFFERS - ... tuning performance Hit ratio does not determine whether a database is optimally tuned Use the Oracle Wait Interface to examine what is causing a bottleneck – v$session_wait – v$session_event – v$system_event Tune SQL statements Copyright © Oracle Corporation, 2002 All rights reserved Guidelines to Increase the Cache Size Increase the cache size ratio under the following conditions: • Any wait events have... (BUFFER_ POOL RECYCLE); ALTER INDEX cust_name_idx STORAGE (BUFFER_ POOL KEEP); 5-28 Copyright © Oracle Corporation, 2002 All rights reserved KEEP Buffer Pool Guidelines • • • Tuning goal: Keeping blocks in memory Size: Holds all or nearly all blocks of the segments assigned to this pool Tool: dbms_stats.gather_table_stats SQL> EXECUTE dbms_stats.gather_table_stats > ('HR','DEPARTMENTS'); SQL> 2 3 4 SELECT... Copyright © Oracle Corporation, 2002 All rights reserved Guidelines for Using the Cache Hit Ratio Hit ratio is affected by data access methods: • Full table scans • Data or application design • Large table with random access • Uneven distribution of cache hits 5-21 Copyright © Oracle Corporation, 2002 All rights reserved Buffer Cache Hit Ratio Isn’t Everything • • • • • 5-22 A badly tuned database can... Provide nonblocking asynchronous I/O requests Are typically not recommended if asynchronous I/O is available Follow the naming convention ora_innn_SID Copyright © Oracle Corporation, 2002 All rights reserved Tuning DBWn I/O Tune the DB Writer processes by looking at the value of the FREE BUFFER WAITS event 5-45 Copyright © Oracle Corporation, 2002 All rights reserved . reserved. Buffer Cache Sizing Parameters • The buffer cache can consist of independent subcaches for buffer pools and for multiple block sizes. • The DB_BLOCK_SIZE. different cache sizes. • DBAs can use the information provided by these statistics to size the buffer cache optimally for a given workload. • The buffer cache