You are on page 1of 29

IBM Software Group

Oracle SQL Tuning and Indexing

2010 IBM Corporation

IBM Software Group | Tivoli software

ADDM Report and AWR Report


ADDM (Automatic Database Diagnostic Monitor) reports findings and gives
recommendations about activities that impact db most. The goal of this
report is to identify those areas that consume most DB Time.
Built in to the database by default, and gives a report every 60 minutes.
Typical Problem that could be fixed by ADDM:
Queries are suddenly taking longer.
Look at the last ADDM report, and look for findings and recommendations.
AWR report is a Workload Repository Report
Built in to database by default, captures data every 30 minutes and purges
data 7 days old.
ADDM examines data in AWR and performs analysis to determine major
issues.
Snapshot Data Collection needs to be enabled to create these reports.

2010 IBM Corporation

IBM Software Group | Tivoli software

AWR Report in Enterprise Manager Console


To create AWR report in Enterprise Manager Console, Go to Performance tab
Click on Snapshots Click on Automatic Workload Repository

Click on Run AWR Report

2010 IBM Corporation

IBM Software Group | Tivoli software

AWR Report - Continued


Select a Beginning Snapshot and Ending Snapshot

2010 IBM Corporation

IBM Software Group | Tivoli software

AWR Report - Continued


Report gets created and Displayed

Report has lot of details, Clicking on View ADDM run button on the same page
will give the findings and recommendations. Appendix slides have a listing of
all the sections in AWR report.

2010 IBM Corporation

IBM Software Group | Tivoli software

Most Useful Sections in AWR report for Sql Tuning

2010 IBM Corporation

IBM Software Group | Tivoli software

ADDM Report in Enterprise Manager Console


The "Performance Analysis" section on the "Home" page is a list of the top
five findings from the last ADDM analysis task in Enterprise Manager
Console.

Alternatively, the ADDM last report created can also be viewed by going to
the Performance tab Advisor Central Click on View Result View Report

2010 IBM Corporation

IBM Software Group | Tivoli software

Example ADDM Report

FINDING 3: 89% impact (5192 seconds) ------------------------------------ SQL statements


consuming significant database time were found. RECOMMENDATION 1: SQL Tuning,
78% benefit (4545 seconds) ACTION: Run SQL Tuning Advisor on the SQL statement
with SQL_ID "5vnwk8kvr2b6j". RELEVANT OBJECT: SQL statement with SQL_ID
5vnwk8kvr2b6j and PLAN_HASH 1787281524 select * from worklog where ((recordkey
in (select wonum from workorder where wogroup= :"SYS_B_0" ) and class in (select
woclass from workorder where wogroup= :"SYS_B_1" ) and siteid= :"SYS_B_2" )) order
by createdate desc RATIONALE: SQL statement with SQL_ID "5vnwk8kvr2b6j" was
executed 14 times and had an average elapsed time of 325 seconds.

2010 IBM Corporation

IBM Software Group | Tivoli software

Tuning Sql Using Oracle Enterprise Manager Console


Enable Snapshot Data Collection
Create a Tuning Set
Create a Tuning Task Using Sql Tuning Advisor
Look for Recommendations

Note: All the above tasks can be achieved by using scripts also. Scripts for
enabling/disabling snapshots, creating tuning set, creating tuning task and for
creating tuning reports are in Appendix slides.

2010 IBM Corporation

IBM Software Group | Tivoli software

Enabling Snapshots using Enterprise Manager Console


Snapshot Data collection is automatically enabled, verify by logging in to
Enterprise Manager Console, Go to Performance tab, Click on Snapshots,
Click on Automatic Workload Repository

10

2010 IBM Corporation

IBM Software Group | Tivoli software

Creating Tuning Task Step 1


In Enterprise Manager Console, Go to Performance Tab Click on Sql
Tuning Set at the Bottom
Click on Create Enter a name and description

11

2010 IBM Corporation

IBM Software Group | Tivoli software

Create a Sql Tuning Set Step 2


Sql Statements can be captured in to Tuning Set either from Cursor Cache
or from AWR Snapshots. In this example Sql Statements are collected from
AWR Snapshots.

12

2010 IBM Corporation

IBM Software Group | Tivoli software

Create a Sql Tuning Set Step 3


If tuning an individual statement, that can be pasted in to Sql Text Field or
defaults can be taken to tune the entire set of Sqls in the Snapshot. Example
is shown using the query Select * from Worklog

13

2010 IBM Corporation

IBM Software Group | Tivoli software

Create a Sql Tuning Set Step 4

Schedule for Tuning set to be created Immediately.

14

2010 IBM Corporation

IBM Software Group | Tivoli software

Create a Sql Tuning Set Step 4

Submit to create the Tuning Task.

15

2010 IBM Corporation

IBM Software Group | Tivoli software

Create a Tuning Task


After creating the Tuning Set Go to Performance Tab and Click on
Advisor Central, Go to Sql Access Advisor.
Select Sql Tuning Set Previously Created.
Select Scope of Analysis as Comprehensive.
Submit the tuning task.

16

2010 IBM Corporation

IBM Software Group | Tivoli software

Tuning Task Results

Notice that Sql given earlier in Sql Text of Tuning set, an occurrence of a
similar corresponding sql was found from the snapshot.
Click on View to view the recommendations.

17

2010 IBM Corporation

IBM Software Group | Tivoli software

Recommendations from Tuning Task

18

2010 IBM Corporation

IBM Software Group | Tivoli software

Compare Execution Plans in Recommendations

19

2010 IBM Corporation

IBM Software Group | Tivoli software

APPENDIX

20

2010 IBM Corporation

IBM Software Group | Tivoli software

ADDM Report
The types of problems that ADDM report provides insight include the following:
CPU bottlenecks - Is the system CPU bound by Oracle or some other
application?
Undersized Memory Structures - Are the Oracle memory structures, such as
the SGA, PGA, and buffer cache, adequately sized?
I/O capacity issues - Is the I/O subsystem performing as expected?
High load SQL statements - Are there any SQL statements which are
consuming excessive system resources?
High load PL/SQL execution and compilation, as well as high load Java
usage
RAC specific issues - What are the global cache hot blocks and objects; are
there any interconnect latency issues?
Sub-optimal use of Oracle by the application - Are there problems with poor
connection management, excessive parsing, or application level lock
contention?
Database configuration issues - Is there evidence of incorrect sizing of log
files, archiving issues, excessive checkpoints, or sub-optimal parameter
settings?
Concurrency issues - Are there buffer busy problems?
Hot objects and top SQL for various problem areas

21

2010 IBM Corporation

IBM Software Group | Tivoli software

AWR Report
Report Summary: This gives an overall summary of the instance during the snapshot period, and
it contains important aggregate summary information.
Cache Sizes (end): This shows the size of each SGA region after AMM has changed them. This
information can be compared to the original init.ora parameters at the end of the AWR report.
Load Profile: This important section shows important rates expressed in units of per second and
transactions per second.
Instance Efficiency Percentages: With a target of 100%, these are high-level ratios for activity in the
SGA.
Shared Pool Statistics: This is a good summary of changes to the shared pool during the snapshot
period.
Top 5 Timed Events: This is the most important section in the AWR report. It shows the top wait
events and can quickly show the overall database bottleneck.
Wait Events Statistics Section: This section shows a breakdown of the main wait events in the
database including foreground and background database wait events as well as time model,
operating system, service, and wait classes statistics.
Wait Events: This AWR report section provides more detailed wait event information for foreground
user processes which includes Top 5 wait events and many other wait events that occurred during
the snapshot interval.
Background Wait Events: This section is relevant to the background process wait events.
Time Model Statistics: Time mode statistics report how database-processing time is spent. This
section contains detailed timing information on particular components participating in database
processing.
22

2010 IBM Corporation

IBM Software Group | Tivoli software

AWR Report - Continued


Operating System Statistics: The stress on the Oracle server is important, and this section shows the
main external resources including I/O, CPU, memory, and network usage.
Service Statistics: The service statistics section gives information about how particular services
configured in the database are operating.
SQL Section: This section displays top SQL, ordered by important SQL execution metrics.
SQL Ordered by Elapsed Time: Includes SQL statements that took significant execution time
during processing.
SQL Ordered by CPU Time: Includes SQL statements that consumed significant CPU time
during its processing.
SQL Ordered by Gets: These SQLs performed a high number of logical reads while retrieving
data.
SQL Ordered by Reads: These SQLs performed a high number of physical disk reads while
retrieving data.
SQL Ordered by Parse Calls: These SQLs experienced a high number of reparsing operations.
SQL Ordered by Sharable Memory: Includes SQL statements cursors which consumed a large
amount of SGA shared pool memory.
SQL Ordered by Version Count: These SQLs have a large number of versions in shared pool
for some reason.

23

2010 IBM Corporation

IBM Software Group | Tivoli software

AWR Report - Continued


Instance Activity Stats: This section contains statistical information describing how the database operated
during the snapshot period.
Instance Activity Stats (Absolute Values): This section contains statistics that have absolute values not
derived from end and start snapshots.
Instance Activity Stats (Thread Activity): This report section reports a log switch activity statistic.
I/O Section: This section shows the all important I/O activity for the instance and shows I/O activity by
tablespace, data file, and includes buffer pool statistics.
Tablespace IO Stats
File IO Stats
Buffer Pool Statistics
Advisory Section: This section show details of the advisories for the buffer, shared pool, PGA and Java
pool.
Buffer Pool Advisory
PGA Aggr Summary: PGA Aggr Target Stats; PGA Aggr Target Histogram; and PGA Memory
Advisory.
Shared Pool Advisory
Java Pool Advisory
Buffer Wait Statistics: This important section shows buffer cache waits statistics.
Enqueue Activity: This important section shows how enqueue operates in the database. Enqueues are
special internal structures which provide concurrent access to various database resources.
Undo Segment Summary: This section gives a summary about how undo segments are used by the
database.
Undo Segment Stats: This section shows detailed history information about undo segment activity.

24

2010 IBM Corporation

IBM Software Group | Tivoli software

AWR Report - Continued


Latch Activity: This section shows details about latch statistics. Latches are a lightweight serialization
mechanism that is used to single-thread access to internal Oracle structures.
Latch Sleep Breakdown
Latch Miss Sources
Parent Latch Statistics
Child Latch Statistics
Segment Section: This report section provides details about hot segments using the following criteria:
Segments by Logical Reads: Includes top segments which experienced high number of logical
reads.
Segments by Physical Reads: Includes top segments which experienced high number of disk
physical reads.
Segments by Buffer Busy Waits: These segments have the largest number of buffer waits
caused by their data blocks.
Segments by Row Lock Waits: Includes segments that had a large number of row locks on their
data.
Segments by ITL Waits: Includes segments that had a large contention for Interested Transaction
List (ITL). The contention for ITL can be reduced by increasing INITRANS storage parameter of the
table.
Dictionary Cache Stats: This section exposes details about how the data dictionary cache is operating.
Library Cache Activity: Includes library cache statistics describing how shared library objects are
managed by Oracle.
SGA Memory Summary: This section provides summary information about various SGA regions.
init.ora Parameters: This section shows the original init.ora parameters for the instance during the
snapshot period.

25

2010 IBM Corporation

IBM Software Group | Tivoli software

Creating an AWR Report


AWR Report can be created by using Oracle Enterprise Manager Console UI or by
using Scripts.
To create the report Snapshot data collection has to be enabled.
Start Snapshot Collection at the beginning of the Test:
- Login in to the database using Sqlplus as Sys user
Example: connect sys/password@db as sysdba
- At Sqlplus Prompt : begin
DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(11520,10); end;
This takes snapshots every ten minutes.
Stop Snapshot Collection at the end of the Test:
- Login in to the database using Sqlplus as Sys user
Example: connect sys/password@db as sysdba
- At Sqlplus Prompt : begin DBMS_WORKLOAD_REPOSITORY.create_snapshot; end;
To Create an AWR Report:
- Login in to the database using Sqlplus as Sys user
Example: connect sys/password@db as sysdba
- At Sqlplus Prompt : <ORACLE_HOME>\RDBMS\ADMIN\awrrpt.sql;
Script will prompt for Report Type - Select HTML, Provide a folder name to Save the Report, Provide
Begin and End Snapshot Numbers.

26

2010 IBM Corporation

IBM Software Group | Tivoli software

Creating an ADDM Report


Similar to AWR report Snapshot data should exist to create the ADDM report.
- Login in to the database using Sqlplus as Sys user
Example: connect sys/password@db as sysdba
- At Sqlplus Prompt : <ORACLE_HOME>\RDBMS\ADMIN\addmrpt.sql;
- Script will prompt for Report Type - Select HTML, Provide a folder name to Save
the Report, Provide Begin and End Snapshot Numbers.
Example ADDM Report:
FINDING 5: 55% impact (3211 seconds)
-----------------------------------The SGA was inadequately sized, causing additional I/O or hard parses.
RECOMMENDATION 1: DB Configuration, 55% benefit (3211 seconds)
ACTION: Increase the size of the SGA by setting the parameter "sga_target" to 2688 M.
ADDITIONAL INFORMATION: The value of parameter "sga_target" was "1536 M"
during the analysis period.
SYMPTOMS THAT LED TO THE FINDING: SYMPTOM: Wait class "User I/O" was
consuming significant database time. (92% impact [5337 seconds])

27

2010 IBM Corporation

IBM Software Group | Tivoli software

Creating an SQL Tuning Task


Adding a Sql Tuning Task and getting Recommendations for the sql in a given snapshot can be
done thru Oracle Enterprise Manager Console UI or using Scripts.
--Login to Sqlplus as Sys
connect sys/perfdb@perfdb as sysdba;
--Create Sql set
exec dbms_sqltune.create_sqlset(sqlset_name => 'TuningSet1', description =>'Tuning Set 1', sqlset_owner =>'SYS');
--Starts collecting Sql Statements from cursor cache for 30 mins and every 5 mins, Change the duration for
longer tests
exec DBMS_SCHEDULER.CREATE_JOB(job_name => 'CREATE_STS_1274217379593', job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN dbms_sqltune.capture_cursor_cache_sqlset( sqlset_name=>''TuningSet1'', time_limit=>''1800'',
repeat_interval=>''300'', sqlset_owner=>''SYS''); END;', enabled => TRUE);
--After the test ends create a tuning task
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sqlset_name => 'TuningSet1',
scope
=> DBMS_SQLTUNE.scope_comprehensive,
time_limit => 3600,
task_name => 'TuningTask1',
description => 'Tuning task for an SQL tuning set1.',
sqlset_owner => 'SYS');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

28

2010 IBM Corporation

IBM Software Group | Tivoli software

Creating an SQL Tuning Task - Continued


--Execute tuning task
EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'TuningTask1');
--Check if Tuning Task Completed
SELECT task_name, status FROM dba_advisor_log WHERE owner = 'SYS';
--Generate a Report, in the spool command give the path/file name to save the report
Spool path\filename;
SET LONG 10000
SET PAGESIZE 1000
SET LINESIZE 200
SET PAGESIZE 24
SELECT DBMS_SQLTUNE.report_tuning_task('TuningTask1') AS recommendations FROM dual;
spool off;

29

2010 IBM Corporation

You might also like