Top Banner
Applying a Applying a Blockcentric Approach Blockcentric Approach to Oracle Tuning to Oracle Tuning Daniel W. Fink Daniel W. Fink www.optimaldba.com www.optimaldba.com
44

Applyinga blockcentricapproachtotuning

Dec 16, 2014

Download

Documents

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java shutdown sequence
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Applyinga blockcentricapproachtotuning

Applying a Applying a Blockcentric Approach Blockcentric Approach to Oracle Tuningto Oracle Tuning

Daniel W. FinkDaniel W. Finkwww.optimaldba.comwww.optimaldba.com

Page 2: Applyinga blockcentricapproachtotuning

Overview

What is Blockcentric Approach?Shifting Focus for Architectural and Tuning Decisions

Myths and Fallacies“Burn him at the stake!”

Applying the MethodWill be addressed throughout the presentation

Page 3: Applyinga blockcentricapproachtotuning

Trust, But Verify

Information presented is generalIt will not cover all scenarios all databasesOnly covers 1 aspect of tuning and architecture

Page 4: Applyinga blockcentricapproachtotuning

“Scientists are by definition highly rational beings who pursue truths supported by hard data.”

- Alisa Smith

Page 5: Applyinga blockcentricapproachtotuning

What is the Blockcentric Approach?

Closely tied to Oracle I/O subsystem

Protecting memory structuresSingle and Multiple Read operations

Shifts focus from Rows to BlocksMany traditional methods focus on rowsI/O system understands blocks

Page 6: Applyinga blockcentricapproachtotuning

Oracle’s I/O Subsytem

Blocks not RowsLogical v. Physical I/OFull Scans

Page 7: Applyinga blockcentricapproachtotuning

Blocks not Rows

Blocks are read, not rowsLarger block sizes means more rows per block

Page 8: Applyinga blockcentricapproachtotuning

Logical I/O

Not just memory accessAccessing Block in memoryRequires locking of various memory structures

Page 9: Applyinga blockcentricapproachtotuning

Physical I/O

Not always disk accessBlock not found in memoryCould be found in os buffer cache or prefetched from disk

Page 10: Applyinga blockcentricapproachtotuning

Full Scans

Able to read multiple blocks at one timeFull Table Scan

Read all blocks up to the High Water Mark

Fast Full Index ScanCan access non-leading columns in concatenated indexes

Page 11: Applyinga blockcentricapproachtotuning

High Water Mark

The High Water Mark is the last block ever formatted to contain data.If the table has experienced high delete activity, the HWM may be set artificially highIf indicated, the only solution is to reorganize the table

Page 12: Applyinga blockcentricapproachtotuning

High Water Mark

H D D D D

HWM

Page 13: Applyinga blockcentricapproachtotuning

Myths and Fallacies

99.999% Buffer Cache Hit Ratio is GOOD% of Rows Returned determines index usageIndex all WHERE columnsFull Table Scans are BADDUAL is a low cost, useful table

Page 14: Applyinga blockcentricapproachtotuning

Buffer Cache Hit Ratio

Higher is not always betterWhat happens when 99% is not good enough?Memory Speed FallacyDetermining Statement Cost

Page 15: Applyinga blockcentricapproachtotuning

Higher Is Not Always Better

It is an indication of hard work, not necessarily smart work

99.999% BCHR requires 100,000 I/Os

Not a good response to user performance problems

Page 16: Applyinga blockcentricapproachtotuning

BCHR Method

Statement #1 – 98% BCHR5000 Logical I/Os100 Physical I/Os

Statement #2 – 50% BCHR400 Logical I/Os200 Physical I/Os

Page 17: Applyinga blockcentricapproachtotuning

What Happens When 99% Is Not Good Enough?

Everything is tuned, but the system is still slow…Add

More MemoryFaster CPUFaster DiskFaster Network

Makes hardware sales reps happy…

Page 18: Applyinga blockcentricapproachtotuning

Memory Speed Fallacy

Disk access is 10,000 times more expensive than Memory Access

Measured in a ‘pure’ environment

In practice, the ratio is closer to 40Request does not go directly to block in cacheThe requested block must be locatedMemory structures must be accessed and manipulatedDisk access may not be actual disk access

Page 19: Applyinga blockcentricapproachtotuning

Determining True Cost of Statements

Compute total cost in terms of I/OLogical I/O costs 1Physical I/O costs 40Cost = LIOs + (PIOs * 40)

Page 20: Applyinga blockcentricapproachtotuning

Blockcentric Method

Statement #1 – 98% BCHR5100 Logical I/Os100 Physical I/OsCost = 5100 + (100 * 40) = 9100

Statement #2 – 50% BCHR400 Logical I/Os200 Physical I/OsCost = 400 + (200 * 40) = 8400

Page 21: Applyinga blockcentricapproachtotuning

% Of Rows Returned

Index usageNumber of Blocks ReturnedData Considerations

Page 22: Applyinga blockcentricapproachtotuning

Index Usage

Use index if % of rows returns is less than

15% for nonparallel5% for parallel

Assumes rows are clusteredrows are read

Page 23: Applyinga blockcentricapproachtotuning

Number Of Blocks Returned

Focus on number of blocks to be readData scattered – many blocks to be readData clustered – fewer blocks to be readData fragmented – many/fewer blocks to be read

Bottom Line – Reduce the Number of Blocks read

Page 24: Applyinga blockcentricapproachtotuning

Scattered DataData of interest is scattered among many blocks

H

Page 25: Applyinga blockcentricapproachtotuning

Pop Quiz 1

A query returns 0.6% of the rows. Match the method with the # of consistent gets (logical I/Os)

A. Full Table Scan 1. 6800B. Index Scan 2. 7200

Page 26: Applyinga blockcentricapproachtotuning

Clustered DataData of interest is present in a few blocks

H

Page 27: Applyinga blockcentricapproachtotuning

Fragmented DataBlocks containing data are interspersed with empty blocks

H

D

D D

D

D

D

Page 28: Applyinga blockcentricapproachtotuning

Pop Quiz 2

A query returns 100% of the rows. Match the method with the # of consistent gets (logical I/Os)

A. Full Table Scan 1. 8500B. Index Scan 2. 6100

Page 29: Applyinga blockcentricapproachtotuning

High Water Mark

H D D D D

HWM

Page 30: Applyinga blockcentricapproachtotuning

Pop Quiz 3

A query returns 100% of the rows. Match the method with the # of consistent gets (logical I/Os)

A. Full Table Scan 1. 1500B. Index Scan 2. 7100

Page 31: Applyinga blockcentricapproachtotuning

Continued Data

Rows are migrated or chainedMultiple I/O operations

Page 32: Applyinga blockcentricapproachtotuning

Index all WHERE Columns

Indexes may speed queriesBut will always slow other operations

Unique constraints require indexesIndex Foreign Keys

Locking problemsJoin column

Page 33: Applyinga blockcentricapproachtotuning

Full Table Scans are BAD

It dependsFocus on # of I/O operations

Multiblock readsData and Block clustering

Focus on ends, not means

Page 34: Applyinga blockcentricapproachtotuning

Determining Block Selectivity

Identify the data to be returned by focusing on the WHERE clauseCalculate the Actual Blocks to be accessed

# of blocks below HWM

# of blocks containing data

Determine how many block selectivity# of Rows with value / # of Blocks with Row

# of Rows with value / # of Blocks below HWM

Page 35: Applyinga blockcentricapproachtotuning

DUAL

Table often used for non-SELECT operationsVery expensive,

Very few I/Os per accessMay actually comprise the largest I/O consumer

SolutionsRewrite codeCreate virtual table

Page 36: Applyinga blockcentricapproachtotuning

Miscellaneous Tuning Tips

Focus on overall length of operationsReduce the I/OsIdentify resource intensive SQL, tune it firstTable and Index MaintenanceMake extent sizes multiples of db_block_size * db_file_multiblock_read_count

Page 37: Applyinga blockcentricapproachtotuning

Focus on overall length of operations

Record ‘Bad’ timeDecide on ‘Good’ timeIdentify where statement is spending most time and tune accordinglyWhen Good time is achieved, stop and move on to the next one

Page 38: Applyinga blockcentricapproachtotuning

Reduce the I/OsAvoid the BCHR Myth

BCHR is not useless, it may indicate problems• Excessively High• Excessively Low

Identify the most expensive statementsFind most I/O IntensiveReduce Logical I/Os…Physical will follow

Reorganize tables when neededHigh Water MarkData or Blocks Not clustered

Page 39: Applyinga blockcentricapproachtotuning

Identify resource intensive SQL – tune it first

Look for statements consuming most I/O

Logical Reads + Physical Reads

Identify tables with most activityDon’t tune 1 query to the detriment of 9 others

Page 40: Applyinga blockcentricapproachtotuning

Table and Index Maintenance

‘Sort tables according to primary key value’ – FallacySort tables to achieve common clusteringRebuild tables and indexes to

Reduce storage requirementsReset high water mark

Page 41: Applyinga blockcentricapproachtotuning

Extent Sizing

Extent sizes should be multiples of multi block read configuration

Multiblock read configuration should match hardware limitations

If extent is 1 block less, multiple I/O calls will be executed

Even if ‘extra’ blocks are empty, it may be more efficient

Page 42: Applyinga blockcentricapproachtotuning

Sources

“Oracle Performance Tuning 101” Vaidyanatha, Deshpande, Kostelac, Jr.“Oracle SQL Tuning Pocket Reference” GurryPerformance Sites

www.hotsos.com - Cary Millsapwww.orapub.com - Craig Shallahamerwww.evdbt.com - Tim Gorman and Jeff Mareshwww.oraperf.com - Anjo Kolk

Page 43: Applyinga blockcentricapproachtotuning

Training Days 2003Rocky Mountain Oracle User Group Training Days 2003

Wednesday, March 5 & Thursday, March 6

Denver ColoradoStay and Ski information available on website

Scheduled speakers includeTim Gorman, Craig Shallahamer, Anjo Kolk, Gary Dodge, Stephan Haisley, John King, Brad Brown, Rachel Carmichael

Details available at www.rmoug.org NYOUG members eligible for Member Rate

Page 44: Applyinga blockcentricapproachtotuning

It is not important to find the right answers.

It is important to ask the right questions.