Professional Documents
Culture Documents
Install Statspack
Install Statspack
Install statspack
cd $ORACLE_HOME/rdbms/admin
sqlplus "/ as sysdba" @spdrop.sql -- Drop and install statspack
sqlplus "/ as sysdba" @spcreate.sql -- Enter tablespace names when
prompted
sqlplus perfstat/perfstat
exec statspack.snap; -- Take a performance snapshots
-- or :
exec perfstat.statspack.snap(i_snap_level=>10); -- or instruct
statspack to do gather more details in the snapshot
-- (look up which
oracle version supports which level).
Statspack reporting
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.
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.
The likely cause of this is because the execution plan has changed. Generate a
current explain plan of the offending query and compare it to a previous one that was
taken when the query was performing well. Usually the previous plan is not available.
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.
It can also happen because of a very high high water mark. Typically when a table was
big, but now only contains a couple of records. Oracle still needs to scan through all
the blocks to see it they contain data.
One can use the index monitoring feature to check if indexes are used by an
application or not. When the MONITORING USAGE property is set for an index, one
can query the v$object_usage to see if the index is being used or not. Here is an
example:
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:
This problem normally only arises when the query plan is being generated by the Cost
Based Optimizer (CBO). The usual cause is because the CBO calculates that
executing a Full Table Scan would be faster than accessing the table via the index.
Fundamental things that can be checked are:
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.
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'.
For example, you may decide that index should be rebuilt if more than 20% of its rows
are deleted:
Here are some of the wait events from V$SESSION_WAIT and V$SYSTEM_EVENT
views:
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
log file sync: If this event is in the top 5, you are committing too often (talk to
your developers)
log file parallel write: deals with flushing out the redo log buffer to disk. Your
disks may be too slow or you have an I/O bottleneck.
Two useful sections in Oracle's Database Performance Tuning Guide:
Both "db file sequential read" and "db file scattered read" events signify time waited for
I/O read requests to complete. Time is reported in 100's of a second for Oracle 8i
releases and below, and 1000's of a second for Oracle 9i and above. Most people
confuse these events with each other as they think of how data is read from disk.
Instead they should think of how data is read into the SGA buffer cache.
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.
The following query shows average wait time for sequential versus scattered reads:
The size of the Redo log buffer is determined by the LOG_BUFFER parameter in your
SPFILE/INIT.ORA file. The default setting is normally 512 KB or (128 KB *
CPU_COUNT), whichever is greater. This is a static parameter and its size cannot be
modified after instance startup.
When a transaction is committed, info in the redo log buffer is written to a Redo Log
File. In addition to this, the following conditions will trigger LGWR to write the contents
of the log buffer to disk:
Statistic "REDO BUFFER ALLOCATION RETRIES" shows the number of times a user
process waited for space in the redo log buffer. This value is cumulative, so monitor it
over a period of time while your application is running. If this value is continuously
increasing, consider increasing your LOG_BUFFER (but only if you do not see
checkpointing and archiving problems).
"REDO LOG SPACE WAIT TIME" shows cumulative time (in 10s of milliseconds)
waited by all processes waiting for space in the log buffer. If this value is low, your log
buffer size is most likely adequate.