IBM Software GroupTuning Sql Using Oracle Enterprise Manager Console Enable Snapshot Data Collection...

29
IBM Software Group © 2010 IBM Corporation Oracle SQL Tuning and Indexing

Transcript of IBM Software GroupTuning Sql Using Oracle Enterprise Manager Console Enable Snapshot Data Collection...

Page 1: IBM Software GroupTuning 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

IBM Software Group

© 2010 IBM Corporation

Oracle SQL Tuning and Indexing

Page 2: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation2

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 ReportBuilt 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.

Page 3: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation3

AWR Report in Enterprise Manager ConsoleTo create AWR report in Enterprise Manager Console, Go to Performance tab

– Click on Snapshots – Click on Automatic Workload Repository

Click on Run AWR Report

Page 4: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation4

AWR Report - Continued

Select a Beginning Snapshot and Ending Snapshot

Page 5: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation5

AWR Report - ContinuedReport 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.

Page 6: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation6

Most Useful Sections in AWR report for Sql Tuning

Page 7: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation7

ADDM Report in Enterprise Manager ConsoleThe "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

Page 8: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation8

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.

Page 9: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation9

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.

Page 10: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation10

Enabling Snapshots using Enterprise Manager ConsoleSnapshot 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

Page 11: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation11

Creating Tuning Task – Step 1In Enterprise Manager Console, Go to Performance Tab – Click on Sql Tuning Set at the BottomClick on Create – Enter a name and description

Page 12: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation12

Create a Sql Tuning Set – Step 2Sql 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.

Page 13: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation13

Create a Sql Tuning Set – Step 3If 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”

Page 14: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation14

Create a Sql Tuning Set – Step 4

Schedule for Tuning set to be created Immediately.

Page 15: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation15

Create a Sql Tuning Set – Step 4

Submit to create the Tuning Task.

Page 16: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation16

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

Page 17: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation17

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.

Page 18: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation18

Recommendations from Tuning Task

Page 19: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation19

Compare Execution Plans in Recommendations

Page 20: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation20

APPENDIX

Page 21: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation21

ADDM ReportThe 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 usageRAC 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

Page 22: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation22

AWR ReportReport 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.

Page 23: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation23

AWR Report - ContinuedOperating 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 whileretrieving 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.

Page 24: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation24

AWR Report - ContinuedInstance 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 StatsFile IO StatsBuffer Pool Statistics

Advisory Section: This section show details of the advisories for the buffer, shared pool, PGA and Java pool.

Buffer Pool AdvisoryPGA Aggr Summary: PGA Aggr Target Stats; PGA Aggr Target Histogram; and PGA Memory

Advisory.Shared Pool AdvisoryJava 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.

Page 25: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation25

AWR Report - ContinuedLatch 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 BreakdownLatch Miss SourcesParent Latch StatisticsChild 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.

Page 26: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation26

Creating an AWR ReportAWR 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.

Page 27: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation27

Creating an ADDM ReportSimilar to AWR report Snapshot data should exist to create the ADDM report.

- Login in to the database using Sqlplus as Sys userExample: 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])

Page 28: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation28

Creating an SQL Tuning TaskAdding 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 Sysconnect sys/perfdb@perfdb as sysdba;

--Create Sql setexec 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 taskDECLARE

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;/

Page 29: IBM Software GroupTuning 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

IBM Software Group | Tivoli software

© 2010 IBM Corporation29

--Execute tuning taskEXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'TuningTask1');

--Check if Tuning Task CompletedSELECT 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 reportSpool path\filename;SET LONG 10000SET PAGESIZE 1000SET LINESIZE 200SET PAGESIZE 24SELECT DBMS_SQLTUNE.report_tuning_task('TuningTask1') AS recommendations FROM dual;spool off;

Creating an SQL Tuning Task - Continued