You are on page 1of 80

#C15LV

Top 10 Oracle database


tuning tips
Session ID#: 442

Guy Harrison,
Executive Director, Information Mgt R&D,
Dell Software Group
@guyharrison

REMINDER
Check in on the
COLLABORATE mobile app

Top 10 Oracle
database tuning tips

Guy Harrison,
Executive Director, Information Mgt
R&D,
Dell Software Group

Introductions

Web:
guyharrison.net
Email: guy.harrison@software.dell.com
Twitter: @guyharrison

Dell Software Group

Dell Software Group

Dell Software Group

Dell Software Group

Dell and Quest a brief history

Dell Software Group

But Seriously

Dell Software Group

The top 10

Dell Software Group

Be methodical and
empirical

Dell - Restricted - Confidential

Hint 1: Methodical and Empirical tuning

11

Dell Software Group

Hint 1: Methodical and Empirical tuning

12

Dell Software Group

Basics of a database request

1. Application send an SQL request


to the database server

Application
Result sets
Return codes

SQL

2. Server compiles the SQL and


prepares for execution

Database Server
Request
Blocks

Return
blocks

3. Server looks for data in memory


first

Server Memory
Request
Blocks

Return
blocks

IO subsystem

13

Dell Software Group

4. If the data is not in memory,


server reads from disk

The 4 layers in database performance

1. Tune SQL and application code to


reduce the logical demand

Application
Result sets
Return codes

SQL

2. Eliminate contention points and


bottlenecks

RDBMS code
Request
Blocks

Return
blocks

3. Configure Memory to avoid as much


IO as possible

Server Memory
Request
Blocks

Return
blocks

IO subsystem

14

Dell Software Group

4. Tune disk IO system to reduce


waits for IO

Whats wrong with the


donkey?

15

Dell Software Group

Measurement

Standard SQL views


AWR reports
DB control/Cloud control
Toad/Spotlight other 3rd party
tools
A single query can tell you a
lot

http
://guyharrison.net/OPSGSam
ples/Ch03/timeModelSimple.
sql

16

Dell Software Group

Database design

Dell - Restricted - Confidential

Database design

18

Dell Software Group

3NF is mostly Dont Repeat Yourself (DRY)

We dont want to repeat the student


name every time they take a new test
We dont want to repeat the test_name
for every student that takes it
We dont want the repeating group of
answers

19

Also, we might not know how many


questions there will be in future tests

Dell Software Group

3NF version

Students take tests


Tests have questions
Students taking tests provide answers

20

Dell Software Group

Dont go to far!
In this example the designer pulled
address into a separate table and city,
country into another table.
Its correct in theory, but it means that
every time we want an employees
address we have to join three tables.
It would have been better to have just
one table

21

Dell Software Group

Logical to Physical: Subtypes

Customers are people too

22

Dell Software Group

Subtypes

Its usually better to put all the data in one table, or have two tables for each subtype
Having a supertype table and two subtype tables means you always have to join
tables

Probably dont
want to do this

23

Dell Software Group

Denormalization

24

Dell Software Group

Index Wisely

Dell - Restricted - Confidential

Indexes

26

Dell Software Group

Concatenated index effectiveness

last,first,birthyear,id

last,first,BirthYear

last+first name

last name

The more columns in the


index the less IO it takes
to resolve a query using
all the columns
The order of the
columns affects how the
index can be used

If the index has all the


columns, dont need to
touch the table at all

63

None
0

1459
200 400 600 800 1000 1200 1400 1600
Logical IO

27

Dell Software Group

SELECT cust_id
FROM sh.customers c
WHERE cust_first_name = 'Connor'
AND cust_last_name = 'Bishop'
AND cust_year_of_birth = 1976;

Index overhead

7
6

14,285

12,727

Number of indexes

Indexes speed up
queries, but make
DML (insert, update,
Delete) slower

16,316

This chart shows how


inserts slow down as
more and more
indexes are added

10,719

8,691

Deleting a row with


lots of indexes is
particularly expensive

6,671

1 (PK only)1,191
0

5,000

10,000

15,000

Logical reads required

28

Dell Software Group

20,000

Index or FTS?
1000

100

Elaspe d Tim e (s )

10

Break even points

Full Scan no caching


Index sorted data, no caching
Index unsorted, cached data

1
0

10

20

30

40

50

60

Pct of table acces se d

29

Dell Software Group

Full Table scan, cached data


70
80
90

100

Application code

Dell - Restricted - Confidential

Database coding guidelines

31

Dell Software Group

Parse overhead

Its easy enough in most programming languages to create a new SQL every time
you execute the query:

32

Dell Software Group

Better to use the same SQL with different


arguments:
Prepare the statement once, then execute many times with
different arguments
Using bind variables

33

Dell Software Group

Reduction in parse (SQL Compile) time

Bind Variables

No Bind variables

200

400

600
Parse Time

1,000 executions of the code on


preceding two slides in Oracle

34

Dell Software Group

800
Other

1000

1200

1400

Designing transactions

There are two ways to design transaction locking


Pessimistic works best if you think someone else is going to grab your row before
youre finished
Optimistic works best if you thing no one else will grab the row

35

Dell Software Group

Reduce Network traffic

Round trips to the database can add a lot of overhead


Two ways to reduce round trips:

36

Use the Array interface in your program code


Use stored procedures for complex interactions with the database

Dell Software Group

Array fetch performance

40,000
35,000
30,000
25,000
20,000
15,000
10,000
5,000
0
0

20

40

60

80

100

Array fetch size


Logical Reads

37

Dell Software Group

Network round trips

120

140

Network stored procedures

A stored procedure is code stored in the database


If you have a transaction that goes back and forth to the database, consider a
stored procedure
ESPECIALLY if you are working across a slow network

38

Dell Software Group

Optimize the
optimizer

Dell - Restricted - Confidential

Table and index


Structure

Cardinality
Estimates

Object Statistics

DB parameters
And config

Optimizer inputs

IO and CPU
Estimates

Remember: Garbage In :
Garbage Out
The optimizer can only do a
good job if statistics are up to
date

40

Dell Software Group

System Statistics

Cost estimate

Histograms

20,000
18,000
16,000
14,000
12,000
10,000
Number of rows

8,000
6,000
4,000
2,000
0

41

Dell Software Group

Indexes are only good for getting


small amounts of the table
So it might be a good idea to use
an index to get New Zealand
customers, but not United
States
A histogram allows the optimizer
to understand how the data is
distributed and make the best
decision
Create histograms to correct bad
plans on skewed tables

Without a histogram

Number of rows
the estimated

Real number of
rows

42

Dell Software Group

Optimizer
chooses not to
use an index

With a histogram

Optimizer
estimate is
correct

Optimizer
chooses to use an
index

43

Dell Software Group

DBMS_STATS

GATHER_INDEX_STATS , GATHER_SCHEMA_STATS,
GATHER_TABLE_STATS

Basic statistics

method_opt

=> 'FOR ALL INDEXED COLUMNS SIZE AUTO'

Histograms

method_opt

=>

Multi-column extended statistics

'FOR ALL COLUMNS FOR COLUMNS (col1, col2)'

method_opt
=> 'FOR ALL COLUMNS FOR COLUMNS
(function(column)))'

Expression extended statistics

DBMS_STATS.gather_system_stats (
gathering_mode => 'NOWORKLOAD');

Non-workload system statistics

DBMS_STATS.gather_system_stats
(gathering_mode
=> 'INTERVAL',
interval
=> 60);

Workload system statistics

44

Dell Software Group

Tune SQL and


PL/SQL

Dell - Restricted - Confidential

Find them and tune them

46

Dell Software Group

V$SQL is your friend

Also, V$SQL_PLAN,
V$SQL_PLAN_STATISTICS
Tkprof, session trace

47

Dell Software Group

48

Dell Software Group

Now lets look at the


donkey

49

Dell Software Group

Monitor and
manage contention

Dell - Restricted - Confidential

Contention the proverbial bottleneck

Application
Demand for DB
services

51

Dell Software Group

Contention for limited or


serialized resources causes
waits and or queuing

Apparent
demand at lower
layers is reduced

Types of contention

Locks
Usually locking problems
are due to application
locks (remember
optimistic locking)?

Sometimes internal locks


can cause problems.

52

Dell Software Group

Latches and
Mutex

Buffer
contention

Latches are very light


weight locks that protect
memory instead of tables

When sessions have to


wait for a memory
buffer to become
available

Latches and mutex contention

Latches are like locks, but


instead of protecting table
rows, they protect memory
(buffers)

user

user

If two sessions try to access


the same area of memory,
then one will wait

Buffers

Instead of sleeping (like a


lock) they waiting session
will spin on the CPU for a
very short time
Latch problems may indicate
hot blocks
They might cause CPU drain
(because of spinning)

53

Dell Software Group

user

Database
files

Free buffer waits


Write to
buffers
User

Buffers

Buffer
Waits
Read
from

When buffers are modified they


are called dirty DBWR writes to
disk

buffers

Read
from
disk

Database
Writer

Write
dirty
blocks
to disk
Database
files

54

Dell Software Group

Database buffers improve


performance by caching data in
memory

When all the blocks are dirty


then sessions have to wait for the
buffers to be written before new
data can be read
This might mean that your DBWR
cant write to disk fast enough

Specific contention scenarios

Lock/Latch

Possible cause

Library cache mutex

Hard parsing no bind variables. Try


CURSOR_SHARING=SIMILAR

Library cache pin

PL/SQL package parsing and invalidations

Shared pool latch

Hard parsing and possibly excessive SGA resizing

Cache buffers chains

Hot blocks, very high logical read rates

Free Buffer waits

DBWR failing to keep up with block changes

Flashback buf free

Insufficient IO bandwidth for flashback area

Buffer busy

Hot blocks partitioning might help

55

Dell Software Group

Optimize memory
to reduce IO

Dell - Restricted - Confidential

Memory is primarily used to avoid IO

Buffer cache avoids IO to table/index


tablespaces
PGA avoids IO to temporary tablespace

57

Dell Software Group

Temp tablespace IO can easily overwhelm


table/index IO

Multi-pass
Disk Sort

Single
Pass
Disk Sort

Memory
Sort
Table/Index IO

More Memory

58

Dell Software Group

Available Memory

CPU Time

Temp Segment IO

Less Memory

Time

Automatic Memory Management


Introduced in 11g, AMM manages allocations between and
within PGA and SGA

59

Dell Software Group

AMM can (rarely?) lead to thrashing or


starvation

ALWAYS set minimum values for key components of the SGA

60

Dell Software Group

Tune IO last, but


tune it well

Dell - Restricted - Confidential

IO Tuning

Disk IO is the slowest part of the database system, so its


critical to performance
FIRST:
Tune SQL and application
Remove contention
Allocate memory

Only when youve done that will your IO demand be


realistic. Then you can tune your IO

62

Dell Software Group

Basics of IO tuning (magnetic disks)

The amount of IO you can support depends on the number of disks you have
Provide enough disks to support the amount of IO you need
even if that means the disks are not filled with data
Magnetics disks can do between 75-150 IO per second (IOPS) do the math!

SAS 15,000 rpm


SAS 10,000 rpm
SATA 10,000 rpm
SATA 7,200 rpm
0

20

40

60

80

100

IO/ps

63

Dell Software Group

120

140

160

180

200

Disk Drive latency


100
90
80

Latency is the time taken to perform a


single IO

70

Most disk drives can return an IO in 5-10 ms

60

Faster if the disk has a memory cache

Disk latency increases with:

Throughput (best at 50-75% of maximum)


Disk fill (best at 50% capacity)

To get best performance disks should be

Sparsely populated
Under only moderate load

RAID 0+1 is the preferred configuration

Response Time (ms)

50
40
30
20
10
0
0

50 100 150 200 250 300 350 400 450


IO/second

64

Dell Software Group

The more that things change....

65

Dell Software Group

Disks are not getting faster

66

Dell Software Group

SSD - Cheaper by the IO

SSD DDR-RAM 15
SSD PCI flash 25
SSD SATA Flash 80
Magnetic Disk

4,000
0

1,000

2,000

Seek time (us)

67

Dell Software Group

3,000

4,000

5,000

But not by
the GB

10

12

10
10
2.9

2.3

2.2
8

7.4

1.7
1.3

$$/GB
1
$$/GB

2011

5.3
2013

2012

2014

3.2

0.35 2.9
0.28
2.2

2.3
1.7
0.21

0.1

Dell Software Group

1.3
0.17

0.35

0.28

0.21

0.17

0.13
0.13

0
2011

2012

2013

2014

2015

HDD

68

2015

MLC SDD

SLC SSD

69

Dell Software Group

$/IOP

$/GB

Tiered storage management

Random reads FusionIO

Table on SSD

Flash cache
IO
DB File IO
Other
CPU

121

SAS disk, flash cache

583

SAS disk, no flash cache

2,211

500

1000

Elapsed time (s)

70

Dell Software Group

1500

2000

2500

Full table scans

Table on SSD

72

Flash cache doesnt


accelerate Full table scans
b/c scans use direct path
reads and flash cache only
accelerates buffered reads

SAS disk, flash cache

398

SAS disk, no flash cache

418

50 100 150 200 250 300 350 400 450

Elasped time (s)

71

Dell Software Group

Flash Cache IO
DB File IO
Other
CPU
Total

Disk Sorts temp tablespace SSD vs HDD

4000
3500
Multi-pass
Disk Sort

3000
2500
2000

Elapsed time (s)

1500
Single Pass
Disk Sort

1000
500
0

300

250

200

150

100

Sort Area Size


SAS based TTS
SSD based TTS
72

Dell Software Group

50

Concurrent redo workload (x10)

Flash based redo log

1,637

331

1,681

Log File IO
Other
CPU
SAS based redo log

1,605

500

397

1,000 1,500 2,000 2,500 3,000 3,500 4,000 4,500


Elapsed time (s)

73

Dell Software Group

1,944

Tune RAC

Dell - Restricted - Confidential

RAC will scale well,


providing that.

a) The time taken to


transfer a block
across
Load is reasonably
well balanced
the
interconnect
across the
instances
in theiscluster
much less than the
time taken to read
The overhead of maintaining cluster
from disk
consistency does not dominate
overall response time

75

Dell Software Group

Toad: your
companio
n in the
Big Data
revolution

76

Dell Software Group

Dell In-Memory Appliances for Cloudera Enterprise

Starter
Configuration

8 Node Cluster
R720- 4 Infrastructure Nodes
R720XD- 4 Data Nodes
Force10- S55
~176TB (disk raw space)
~1.5TB (raw memory)

Mid-Size Configuration
16 Node Cluster
R720- 4 Infrastructure Nodes
R720XD- 12 Data Nodes
Force10- S4810P
Force10- S55
~528TB (disk raw space)
~4.5 TB (raw memory)

Small Enterprise
Configuration

24 Node Cluster
R720- 4 Infrastructure Nodes
R720XD- 20 Data Nodes
~880TB (disk raw space)
~7.5 TB (raw memory)

Expansion Unit- R720XD-4 Data, Cloudera Enterprise Data Hub, Scale


in Blocks

77

Dell Software Group

Dell appliances for any database


Dell provides appliances and reference
architectures specifically designed for:

78

Oracle
SQL Server
HANA
SSD database acceleration
Large memory footprints

Dell Software Group

Thank you.

79

Dell Software Group

#C15LV

Please complete the session


evaluation
We appreciate your feedback and insight

You may complete the session evaluation either


on paper or online via the mobile app

You might also like