Oracle Database Performance Tuning FAQ
Oracle Database Performance Tuning FAQ
Contents
• 1 Why and when should one tune?
• 2 Where should the tuning effort be directed?
• 3 What tools/utilities does Oracle provide to assist with performance tuning?
• 4 When is cost based optimization triggered?
• 5 How can one optimize %XYZ% queries?
• 6 Where can one find I/O statistics per table?
• 7 My query was fine last week and now it is slow. Why?
• 8 Does Oracle use my index or not?
• 9 Why is Oracle not using the damn index?
• 10 When should one rebuild an index?
• 11 How does one tune Oracle Wait event XYZ?
• 12 What is the difference between DBFile Sequential and Scattered Reads?
2
Why and when should one tune?
One of the biggest responsibilities of a DBA is to ensure that the Oracle database is tuned properly.
The Oracle RDBMS is highly tunable and allows the database to be monitored and adjusted to
increase its performance.
• The speed of computing might be wasting valuable human time (users waiting for response);
• Enable your system to keep-up with the speed business is conducted; and
• Optimize hardware usage to save money (companies are spending millions on hardware).
Although this site is not overly concerned with hardware issues, one needs to remember than you
cannot tune a Buick into a Ferrari.
Poor system performance usually results from a poor database design. One should generally
normalize to the 3NF. Selective denormalization can provide valuable performance
improvements. When designing, always keep the "data access path" in mind. Also look at
proper data partitioning, data replication, aggregation tables for decision support systems,
etc.
• Application Tuning:
Experience showed that approximately 80% of all Oracle system performance problems are
resolved by coding optimal SQL. Also consider proper scheduling of batch tasks after peak
working hours.
• Memory Tuning:
Properly size your database buffers (shared_pool, buffer cache, log buffer, etc) by looking at
your wait events, buffer hit ratios, system swapping and paging, etc. You may also want to
pin large objects into memory to prevent frequent reloads.
Database files needs to be properly sized and placed to provide maximum disk subsystem
throughput. Also look for frequent disk sorts, full table scans, missing indexes, row
chaining, data fragmentation, etc.
3
• Eliminate Database Contention:
Study database locks, latches and wait events carefully and eliminate where possible.
Monitor and tune operating system CPU, I/O and memory utilization. For more information,
read the related Oracle FAQ dealing with your specific operating system.
Generally, the CBO can change the execution plan when you:
If the index is physically smaller than the table (which is usually the case) it will take less time to
scan the entire index than to scan the entire table.
4
Where can one find I/O statistics per table?
The STATSPACK and UTLESTAT reports show I/O per tablespace. However, they do not show
which tables in the tablespace has the most I/O operations.
For more details, look at the header comments in the catio.sql script.
• Which tables are currently analyzed? Were they previously analyzed? (ie. Was the query
using RBO and now CBO?)
• Has OPTIMIZER_MODE been changed in INIT<SID>.ORA?
• Has the DEGREE of parallelism been defined/changed on any table?
• Have the tables been re-analyzed? Were the tables analyzed using estimate or compute? If
estimate, what percentage was used?
• Have the statistics changed?
• Has the SPFILE/ INIT<SID>.ORA parameter DB_FILE_MULTIBLOCK_READ_COUNT
been changed?
• Has the INIT<SID>.ORA parameter SORT_AREA_SIZE been changed?
• Have any other INIT<SID>.ORA parameters been changed?
What do you think the plan should be? Run the query with hints to see if this produces the required
performance.
5
Index altered.
SQL>
SQL> SELECT table_name, index_name, monitoring, used FROM v$object_usage;
TABLE_NAME INDEX_NAME MON USE
------------------------------ ------------------------------ --- ---
T1 T1_IDX YES NO
To reset the values in the v$object_usage view, disable index monitoring and re-enable it:
Remember that you MUST supply the leading column of an index, for the index to be used (unless
you use a FAST FULL SCAN or SKIP SCANNING).
There are many other factors that affect the cost, but sometimes the above can help to show why an
index is not being used by the CBO. If from checking the above you still feel that the query should
be using an index, try specifying an index hint. Obtain an explain plan of the query either using
TKPROF with TIMED_STATISTICS, so that one can see the CPU utilization, or with
AUTOTRACE to see the statistics. Compare this to the explain plan when not using an index.
6
When should one rebuild an index?
You can run the ANALYZE INDEX <index> VALIDATE STRUCTURE command on the affected
indexes - each invocation of this command creates a single row in the INDEX_STATS view. This
row is overwritten by the next ANALYZE INDEX command, so copy the contents of the view into
a local table after each ANALYZE. The 'badness' of the index can then be judged by the ratio of
'DEL_LF_ROWS' to 'LF_ROWS'.
• db file sequential read: Tune SQL to do less I/O. Make sure all objects are analyzed.
Redistribute I/O across disks.
• buffer busy waits: Increase DB_CACHE_SIZE (DB_BLOCK_BUFFERS prior to 9i)/
Analyze contention from SYS.V$BH
• log buffer space: Increase LOG_BUFFER parameter or move log files to faster disks
A sequential read operation reads data into contiguous memory (usually a single-block read with
p3=1, but can be multiple blocks). Single block I/Os are usually the result of using indexes. This
event is also used for rebuilding the controlfile and reading datafile headers (P2=1). In general, this
event is indicative of disk contention on index reads.
Similar to db file sequential reads, except that the session is reading multiple data blocks and
scatters them into different discontinuous buffers in the SGA. This statistic is NORMALLY
indicating disk contention on full table scans. Rarely, data from full table scans could be fitted into a
contiguous buffer area, these waits would then show up as sequential reads instead of scattered
reads.
7
The following query shows average wait time for sequential versus scattered reads: