9 Copyright © 2006, Oracle. All rights reserved. Tuning the Buffer Cache.

Slides:



Advertisements
Similar presentations
Database Tuning. Objectives Describe the roles associated with database tuning. Describe the dependency between tuning in different development phases.
Advertisements

Office of the Accountant General (A&E) Andhra Pradesh Hyderabad
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
The Architecture of Oracle
IO Waits Kyle Hailey #.2 Copyright 2006 Kyle Hailey Waits Covered in this Section  db file sequential read  db file scattered.
5 Copyright © 2005, Oracle. All rights reserved. Managing Database Storage Structures.
Buffer Cache Waits. #.2 Copyright 2006 Kyle Hailey Buffer Cache Waits Waits Disk I/O Buffer Busy Library Cache Enqueue SQL*Net Free Buffer Hot Blocks.
Acknowledgments Byron Bush, Scott S. Hilpert and Lee, JeongKyu
Overview of Database Administrator (DBA) Tools
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 2 Overview of Database Administrator (DBA) Tools.
Oracle Architecture. Instances and Databases (1/2)
Page Footer Keed Education Oracle Database Administration Basic Copyright 2009 Keed Education BV Version Concept.
INTRODUCTION TO ORACLE DATABASE ADMINISTRATION Lynnwood Brown System Managers LLC Introduction – Lecture 1 Copyright System Managers LLC 2007 all rights.
13 Copyright © 2005, Oracle. All rights reserved. Performance Management.
13 Copyright © 2007, Oracle. All rights reserved. Performance Management.
15 Copyright © 2004, Oracle. All rights reserved. Monitoring and Managing Memory.
12 Copyright © 2005, Oracle. All rights reserved. Proactive Maintenance.
1 - Oracle Server Architecture Overview
Harvard University Oracle Database Administration Session 2 System Level.
Oracle Architectural Components
10 Copyright © 2006, Oracle. All rights reserved. Automatic Shared Memory Management.
Oracle 10g Database Administrator: Implementation and Administration Chapter 14 Proactive Maintenance.
Oracle Architecture. Database instance When a database is started the current state of the database is given by the data files, a set of background (BG)
1 Copyright © 2005, Oracle. All rights reserved. Introduction.
1 Copyright © 2009, Oracle. All rights reserved. Exploring the Oracle Database Architecture.
12 Copyright © 2007, Oracle. All rights reserved. Database Maintenance.
15 Copyright © 2004, Oracle. All rights reserved. Proactive Maintenance.
2 Copyright © 2006, Oracle. All rights reserved. Performance Tuning: Overview.
Oracle Documentation Oracle DBA Course (9i, 10g, 11g) Lecture 1: Oracle Architectural Components.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
Oracle on Windows Server Introduction to Oracle10g on Microsoft Windows Server.
Basic Oracle Architecture
By Lecturer / Aisha Dawood 1.  You can control the number of dispatcher processes in the instance. Unlike the number of shared servers, the number of.
CSE 781 – DATABASE MANAGEMENT SYSTEMS Introduction To Oracle 10g Rajika Tandon.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Oracle9i Performance Tuning Chapter 2 Tuning the Buffer Cache.
Oracle Tuning Considerations. Agenda Why Tune ? Why Tune ? Ways to Improve Performance Ways to Improve Performance Hardware Hardware Software Software.
Oracle Tuning Ashok Kapur Hawkeye Technology, Inc.
Copyright © Oracle Corporation, All rights reserved. 1 Oracle Architectural Components.
An Oracle server:  Is a database management system that provides an open, comprehensive, integrated approach to information management.  Consists.
13 Copyright © 2006, Oracle. All rights reserved. Tuning PGA and Temporary Space.
15 Copyright © 2006, Oracle. All rights reserved. Performance Tuning: Summary.
© Dennis Shasha, Philippe Bonnet 2001 Log Tuning.
The Self-Managing Database: Automatic SGA Memory Management Tirthankar Lahiri Senior Manager, Distributed Cache & Memory Management Oracle Corporation.
1 Chapter 17 Shared Memory Contention. 2 Overview Specifically talking about SGA – Buffer Cache – Redo Log Buffer Contention in these areas of SGA – Can.
Process Architecture Process Architecture - A portion of a program that can run independently of and concurrently with other portions of the program. Some.
1 Copyright © 2005, Oracle. All rights reserved. Introduction.
11 Copyright © 2006, Oracle. All rights reserved. Checkpoint and Redo Tuning.
1 Logical I/O Julian Dyke Independent Consultant Web Version juliandyke.com © 2005 Julian Dyke.
INTRODUCTION TO ORACLE DATABASE ADMINISTRATION Lynnwood Brown President System Managers LLC Introduction – Lecture 1 Copyright System Managers LLC 2003.
Instance and Media Recovery Structures Supinfo Oracle Lab. 7.
Chapter 1Oracle9i DBA II: Backup/Recovery and Network Administration 1 Chapter 1 Backup and Recovery Overview MSCD642 Backup and Recovery.
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
Preface 1Performance Tuning Methodology: A Review Course Structure 1-2 Lesson Objective 1-3 Concepts 1-4 Determining the Worst Bottleneck 1-5 Understanding.
3 Copyright © 2004, Oracle. All rights reserved. Creating an Oracle Database.
7 Copyright © Oracle Corporation, All rights reserved. Instance and Media Recovery Structures.
14 Copyright © 2005, Oracle. All rights reserved. Backup and Recovery Concepts.
3 Copyright © 2004, Oracle. All rights reserved. Database Architecture Comparison.
1 Copyright © 2006, Oracle. All rights reserved. Introduction.
6 Copyright © 2005, Oracle. All rights reserved. Managing Database Storage Structures.
14 Copyright © 2007, Oracle. All rights reserved. Backup and Recovery Concepts.
4 Copyright © 2004, Oracle. All rights reserved. Managing the Oracle Instance.
5 Copyright © 2005, Oracle. All rights reserved. Managing the Oracle Instance.
Oracle Database Architectural Components
1 Copyright © 2005, Oracle. All rights reserved. Oracle Database Administration: Overview.
Chapter 21 SGA Architecture and Wait Event Summarized & Presented by Yeon JongHeum IDS Lab., Seoul National University.
Initialization Parameters
Index Index.
Presentation transcript:

9 Copyright © 2006, Oracle. All rights reserved. Tuning the Buffer Cache

Copyright © 2006, Oracle. All rights reserved. 9-2 Objectives After completing this lesson, you should be able to do the following: Describe the buffer cache architecture Size the buffer cache Resolve common performance issues related to the buffer cache Use common diagnostic indicators to suggest a possible solution

Copyright © 2006, Oracle. All rights reserved. 9-3 Spfile Temp Data file Undo Oracle Database Architecture PMON SMON RECO MMON MMNL PSP0 MMANDBWnLGWR CKPT CJQ0 S000 D000 QMNC Qnnn FMON ARCn CTWR RVWR Fixed size Shared pool Large pool Java pool Streams pool Default buffer cache Keep buffer cache Recycle buffer cache nK buffer caches Redo log buffer ASH buffer Sort extent pool Global context pool SGA Flash back buffer Instance Flashback logs Redo log files Archive log files Control files SYSTEM SYSAUX Change tracking file Password file

Copyright © 2006, Oracle. All rights reserved. 9-4 Buffer Cache: Highlights Scalable architecture: –Multiversion concurrency control –Proprietary LRU-based replacement policy –Cache fusion Incremental checkpointing mechanism Advisors Private pool for I/O intensive operations

Copyright © 2006, Oracle. All rights reserved. 9-5 Database Buffers SGA DB buffer cache DBWn Server

Copyright © 2006, Oracle. All rights reserved. 9-6 Buffer Hash Table For Lookups Hash buckets table Cache buffer chains latches Buffer hash chains CR clones Buffer headers A B C C E F Buffer cache C CE A B F

Copyright © 2006, Oracle. All rights reserved. 9-7 Working Sets Default Keep Recycle n K Buffer cache C A B A C Working set 1 Working set 2 Auto-tuned … D F E D F B D E F Buffer cache LRUCKPTs LRUCKPTs C A

Copyright © 2006, Oracle. All rights reserved. 9-8 Notes only page

Copyright © 2006, Oracle. All rights reserved. 9-9 Tuning Goals and Techniques It is recommended to use Automatic Shared Memory Management (ASMM). Tuning goals: –Servers find data in memory –No waits on the buffer cache Diagnostic measures: –Wait events –The V$DB_CACHE_ADVICE view and cache hit ratio Tuning techniques: –Review ADDM recommendations if ASMM is used. –Reduce the number of blocks required by SQL statements. –Increase buffer cache size, use multiple buffer pools.

Copyright © 2006, Oracle. All rights reserved Notes only page

Copyright © 2006, Oracle. All rights reserved Symptoms The symptoms that indicate a buffer cache problem: Latch:cache buffer chains Latch:cache buffer LRU chains Buffer busy waits Read waits Free buffer waits Cache hit ratio

Copyright © 2006, Oracle. All rights reserved Cache Buffer Chains Latch Contention Contention for this latch indicates: Multiple processes attempting to access the same “hot” block Excessive block replacement

Copyright © 2006, Oracle. All rights reserved Finding Hot Segments Characteristics of cache buffer chains latch contention: –Many accesses to one or more block under the same latch –Worse with larger block sizes To find hot segments: SQL> SELECT * FROM ( SELECT owner, object_name, 2 object_type, statistic_name, sum(value) 3 FROM V$SEGMENT_STATISTICS 4 GROUP BY owner, object_name, object_type, 5 statistic_name 6 ORDER BY SUM(value) DESC) 7 WHERE ROWNUM < 10;

Copyright © 2006, Oracle. All rights reserved Buffer Busy Waits Application-level contention for buffers in the buffer cache Identify buffer busy waits contention: SELECT object_name, value FROM V$SEGMENT_STATISTICS WHERE statistic_name 'buffer busy waits' AND value > 20000; SELECT class, count FROM V$WAITSTAT WHERE count>0 ORDER BY count DESC;

Copyright © 2006, Oracle. All rights reserved Calculating the Buffer Cache Hit Ratio SELECT name, value FROM v$sysstat WHERE name IN ('db block gets from cache', 'consistent gets from cache', 'physical reads cache'); PHYSICAL READS = 'physical reads cache') LOGICAL READS = ('consistent gets from cache' + 'db block gets from cache') HIT RATIO = 1 - PHYSICAL READS/LOGICAL READS

Copyright © 2006, Oracle. All rights reserved Buffer Cache Hit Ratio Is Not Everything A badly tuned database can still have a hit ratio of 99% or better. Hit ratio is only one part in determining tuning performance. Hit ratio does not determine whether a database is optimally tuned. Use the wait interface to examine what is causing a bottleneck: – V$SESSION_WAIT – V$SESSION_EVENT – V$SYSTEM_EVENT Tune SQL statements.

Copyright © 2006, Oracle. All rights reserved Interpreting Buffer Cache Hit Ratio Hit ratio is affected by data access methods: –Full table scans –Repeated scans of the same tables –Large table with random access –Data or application design Investigate increasing the cache size if: –Hit ratio is low –Application is tuned to avoid full table scans

Copyright © 2006, Oracle. All rights reserved. 9-18

Copyright © 2006, Oracle. All rights reserved Read Waits List of wait events performing disk reads into the buffer cache: – db file sequential read – db file parallel read – db file scattered read If wait time for reads is high: –Tune the SQL statement that issues most disk reads by sorting V$SQL by DISK_READS and BUFFER_GETS. –Grow buffer cache if needed. –Reduce writes due to checkpointing. –Add more disk capacity.

Copyright © 2006, Oracle. All rights reserved. 9-20

Copyright © 2006, Oracle. All rights reserved Free Buffer Waits K B J A C D LRU list Server Write Buffer state dirty free DBWn

Copyright © 2006, Oracle. All rights reserved Solutions The buffer cache solutions are applied depending on the symptoms: Properly size the buffer cache. Cache objects. Use the keep and recycle pools. Increase the writing speed of DBWn. Use private I/O pool.

Copyright © 2006, Oracle. All rights reserved Sizing the Buffer Cache Buffer cache size affects several tuning diagnostics. If the cache is too small: Extra reads due to block replacement Extra writes to move dirty blocks to disk Buffer cache LRU chains contention

Copyright © 2006, Oracle. All rights reserved Buffer Cache Size Parameters Set the primary block size for the recycle, keep, and default buffer pools: DB_BLOCK_SIZE Set the size of the buffer pools: – DB_CACHE_SIZE – DB_KEEP_CACHE_SIZE – DB_RECYCLE_CACHE_SIZE Represent all memory for the buffer cache Are required to use buffer cache features: –Dynamic grow/shrink –Buffer cache advice –Multiple block sizes

Copyright © 2006, Oracle. 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. 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.

Copyright © 2006, Oracle. 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 cache sizes between 10% and 200% of the current cache size. The rows also compute a physical read factor, which is the ratio of the number of estimated reads to the number of actual reads. Simulation is done for all buffer pools.

Copyright © 2006, Oracle. All rights reserved Using the V$DB_CACHE_ADVICE View SELECT size_for_estimate, buffers_for_estimate, estd_physical_read_factor, estd_physical_reads FROM V$DB_CACHE_ADVICE WHERE name = 'DEFAULT' AND advice_status = 'ON' AND block_size = (SELECT value FROM V$PARAMETER WHERE name = 'db_block_size'); Estd Phys Estd Phys Cache Size (MB) Buffers Read Factor Reads (10%) 30 3, ,317,943 … , ,720, , ,583,180 (Current) , ,282, , ,515,878 … , ,895,122 (200%) , ,739,731

Copyright © 2006, Oracle. All rights reserved Using the Buffer Cache Advisory with EM

Copyright © 2006, Oracle. All rights reserved Caching Tables Enable caching during full table scans by: –Creating the table with the CACHE clause –Altering the table with the CACHE clause –Using the CACHE hint in a query: select /* + cache */ Caching tables put blocks at the MRU end of the LRU list. Guideline: Do not overcrowd the buffer cache. Use a keep pool.

Copyright © 2006, Oracle. All rights reserved Multiple Buffer Pools Three buffer pools: –Default: SYS and nonflagged table or indexes –Keep: Hot objects –Recycle: Infrequent access Useful for small, simple schemas with well-known access paths Default Keep Recycle Auto-tuned

Copyright © 2006, Oracle. All rights reserved Notes only page

Copyright © 2006, Oracle. All rights reserved Enabling Multiple Buffer Pools Use the BUFFER_POOL clause. This clause is valid for tables, clusters, and indexes. When altered, buffer pool is used for future reads. Objects can have more than one buffer pool. CREATE INDEX cust_idx … STORAGE (BUFFER_POOL KEEP …); ALTER TABLE customer STORAGE (BUFFER_POOL RECYCLE); ALTER INDEX cust_name_idx STORAGE (BUFFER_POOL KEEP); Buffer pool 이 변경 - 새로 읽어 들인 블록은 새로운 buffer pool 에 들어감 - 이전에 남아 있던 블록은 유지 (flush out 될때까지 )

Copyright © 2006, Oracle. All rights reserved Calculating the Hit Ratio for Multiple Pools SQL> SELECT name, 1 - (physical_reads / 2 (db_block_gets + consistent_gets)) "HIT_RATIO" 3 FROM V$BUFFER_POOL_STATISTICS 4 WHERE db_block_gets + consistent_gets > 0; NAMEHIT_RATIO KEEP RECYCLE DEFAULT

Copyright © 2006, Oracle. All rights reserved Notes only page

Copyright © 2006, Oracle. All rights reserved Multiple Block Sizes Allow buffer caches for nonstandard block sizes Parameters: DB_ n K_CACHE_SIZE { n = 2, 4, 8, 16, 32} BLOCKSIZE attribute of CREATE TABLESPACE storage clause Intended for transportable tablespaces Default Keep Recycle 16 KB cache Set#1 Set#2 Set#3 Set#4 Set#5 Set#6 Set#7 Set#8

Copyright © 2006, Oracle. All rights reserved Multiple Database Writers Multiple database writers are a means to increase write throughput useful for large SMP systems. Buffer cache is partitioned between database writers by working sets. Each DBWn process scans its own assigned sets. The number of database writes can be manually controlled by DB_WRITER_PROCESSES. Set#1 Set#3 Set#2 Set#4 DBW0 DBW1

Copyright © 2006, Oracle. All rights reserved Multiple I/O Slaves Allow DBW0 to write in parallel when asynchronous I/O is not well supported DBW0 gathers batch of buffers Queues batch in round-robin order with I/O slaves Waits for all slaves to complete Cannot combine multiple DBWn with multiple I/O slaves Controlled by: – DBWR_IO_SLAVES – DISK_ASYNCH_IO Set#1 Set#2 Set#3 Set#4 i000 i002 DBW0 i001

Copyright © 2006, Oracle. All rights reserved Use Multiple Writers or I/O Slaves To reduce free buffer waits: Implement asynchronous I/O first Use multiple writers when a database writer is consuming 100% of a CPU Use I/O slaves when asynchronous I/O is not supported

Copyright © 2006, Oracle. All rights reserved Private Pool for I/O Intensive Operations Use for operations that: –Do not require caching –Require efficient I/O Use for large asynchronous I/O Requires global checkpoint to ensure consistent data Use only for direct path I/O: –Parallel direct inserts –SQL*Loader direct path : 직접 쓰기

Copyright © 2006, Oracle. All rights reserved Automatically Tuned Multiblock Reads DB_FILE_MULTIBLOCK_READ_COUNT is automatically tuned. Simplifies the determination of the best value Optimal I/O size is platform dependent: –Cannot exceed 10% of the cache Prefetch limited to 64 KB –Prevents swamping of the cache Automatically enabled if not set or set to zero

Copyright © 2006, Oracle. All rights reserved Faster Instance Startup for Ultralarge Buffer Caches Database available at 10% initialization of buffer cache Remaining 90% formatted in the background by CKPT Leverages the dynamic buffer cache infrastructure Especially useful for very large buffer caches

Copyright © 2006, Oracle. All rights reserved Flushing the Buffer Cache (for Testing Only) ALTER SYSTEM FLUSH BUFFER_CACHE;

Copyright © 2006, Oracle. All rights reserved Practice: Overview This practice covers the following topics: Use the DB Buffer Cache Advisor to size the buffer cache Use the Keep Pool

Copyright © 2006, Oracle. All rights reserved Summary In this lesson, you should have learned how to: Describe the buffer cache architecture Size the buffer cache Resolve common performance issues related to the buffer cache Use common diagnostic indicators to suggest a possible solution