Oracle Performance Tuning Basic PDF
Oracle Performance Tuning Basic PDF
Performance Tuning
Amit Kumar
May 22nd 2007
Explain Plan for this session
• The Problem
• Good performance habits
• The approach
• Define the problem
• Instance Tuning: Examine OS
• Instance Tuning: Examine Oracle Stats
• Instance Tuning: Implement and measure changes
• Using SQL Trace and TKPROF
• SQL Trace File Example
• Formatting Trace Files with TKPROF
• TKPROF File Example
• Understanding Explain Plan – Query Optimizer
• Optimizer Statistics Gathering
• Troubleshooting Network Performance
The Problem
essappu41:/apps/alice/aliceappl/fnd/11.5.0/resource> vmstat -S 5 1
kthr memory page disk faults cpu
r b w swap free si so pi po fr de sr m0 m1 m3 m4 in sy cs us sy id
0 0 0 53270408 12000224 0 0 148 65 62 0 0 0 0 0 0 3353 7206 4838 27 5 67
OWI Philosophy:
• The OWI is a performance tracking methodology that
focuses on process bottlenecks, better known as “wait
events”.
• OWI includes waits for I/O, locks, latches, background
processes, network latencies …
• OWI records and presents all the bottlenecks that a
process encounters from start to finish.
• Keeps tracks of the number of times and amount of
time a process spent on each bottleneck.
• Removing or even reducing the impact of major
bottleneck improves performance.
Instance Tuning: Oracle Wait Interface
• OWI Components:
A collection of a few dynamic performance views and
extended SQL trace file.
OWI provides statistics for wait events to tell how many
times and how long the session waited for an event to
complete.
• V$EVENT_NAME – not a dynamic view. Contains all the
wait events defined for your database.
• V$SYSTEM_EVENT – displays aggregated stats for all
wait events encountered by all oracle sessions since the
instance startup.
• V$SESSION_EVENT – contains aggregated wait event
stats by session for all sessions currently connected to
the instance.
• V$SESSION_WAIT – provides details info about the event
or resource that each session is waiting for
Instance Tuning: Oracle Wait Interface
• Tkprof <trace file> <tkprof output file name> sort=exeela fchela waits=yes
explain=<user/passwd>
TKPROF File Example 1
TKPROF: Release 9.2.0.6.0 - Production on Fri Oct 21 18:04:27 2005
********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************
alter session set events='10046 trace name context forever, level 12'
• OPTIMIZER_FEATURES_ENABLE=10.0.0
• A nested-loop join reads the first row from the driving table, or outer table, and
checks the other table, called the inner table, for the value. Nested-loops work
best when the driving table is rather small and a unique index is defined on the
inner table’s join table.
Query Optimizer – Choice of Join Orders
• Hash Join are used for joining large data sets. A hash table on the smaller table
join key is built in memory. Larger table is then scanned probing the hash table
to find the joined rows. However, if hash table grows too big to fit into memory,
it is broken to into different partitions. As hash table partitions exceeds allocated
memory, parts are written to disk temp segments. After hash table creation,
larger table is scanned, broken into partitions written to disk temp segments.
Finally each hash table partition is read into memory and corresponding partition
for larger table is scanned probing the hash table partition to find the joined
rows. This process is repeated for all partitions.
Query Optimizer – Choice of Join Orders
• A sort-merge join reads both of the joined tables by the join column and
then matches the output from these sorts. The big difference between
this join and the nested-loop is that in the sort-merge, no rows are
returned until after this matching process completes, where as the
nested-loop returns rows almost immediately. Sort-merge joins work
better with larger amounts of data or in situations where two joining
tables are roughly the same size and most of the rows are returned.
• Cluster joins are used instead of nested-loops when the join condition is
making reference to tables that are physically clustered together. The
CBO recognizes this condition and uses it when the tables being joined
are in the same cluster. Table are candidates for clustering when they
joined together and no other queries are typically run against one or the
other.
Query Optimizer – Choice of Join Orders
• Index joins work on the concept that if all the information required for
the SQL statement is found in the index, the underlying table structure is
not accessed or referenced in the execution plan.
• Can table monitoring and STATISTICS_LEVEL = typical be used with 10g DB and
E-business suite?
• Use ping command to find out latency between db tier and apps tier. Use
packet size of 2k (not default 32 bytes) since this is default packet size for
Sqlnet Net traffic.
> ping -s oracledb 2048
PING oracledb: 2048 data bytes
2056 bytes from oracledb (10.237.129.90): icmp_seq=0. time=1. ms
2056 bytes from oracledb (10.237.129.90): icmp_seq=1. time=1. ms
2056 bytes from oracledb (10.237.129.90): icmp_seq=2. time=1. ms
2056 bytes from oracledb (10.237.129.90): icmp_seq=3. time=1. ms
2056 bytes from oracledb (10.237.129.90): icmp_seq=4. time=1. ms
2056 bytes from oracledb (10.237.129.90): icmp_seq=5. time=1. ms
----oracledb PING Statistics----
6 packets transmitted, 6 packets received, 0% packet loss
round-trip (ms) min/avg/max = 1/1/1
Troubleshooting Network Performance
• Use ping command from client to find out latency between client and
apps tier. Vary the packet size to determine the average latency.
C:\Documents and Settings\amit_kumar>ping aptier -l 2048
Pinging aptier [10.237.129.11] with 2048 bytes of data:
1.
– Enable user level trace with binds and waits for application user
“SYSADMIN”
– Log off, login again as SYSADMIN and submit “Active Users” report
– Disable trace and log off
– Identify trace file of “Active Users” report
– Read the trace file and find out bind variables being used
– Do a tkprof on trace and analyze the tkprof
• 2
– A end user complains that production oracle applications is running
very slow. List down your steps you will be performing to check
application and database performance
Thank You