Mining the AWR to Identify Performance Trends
Sometimes it's useful to check how performance of a SQL statement changes over time. The diagnostic pack features provide some really useful information to answer these questions. The data is there, but it not always easy to retrieve it, especially if you want to see how the performance changes over time. I've been using three really simple scripts to retrieve this information from the AWR. These scripts help me answer the following questions:
- How does the performance of a particular SQL change over time?
- How do wait times of a particular wait event change over time?
- How does a particular statistic change over time?
SQL performance
I use script awr_sqlid_perf_trend.sql to check how performance of the SQL changes over time. The script summarizes the data from DBA_HIST_SQLSTAT and reports the average statistics for a single execution of the query during the reporting interval. It requires 3 input parameters:- SQL ID
- Days to report. It will summarize all AWR snapshots starting with "trunc(sysdate)-{days to report}+1", so if you pass "1", it will summarize all snapshots from today, if "2" - than it's yesterday and today are included.
- Interval in hours. "24" will provide one row for each day, "6" will give 4 rows a day.
Wait event performance
Script awr_wait_trend.sql can be used to show the changes in wait counts and wait durations for a particular event over time. Similarly to the previous script it also requires 3 parameters, only instead of SQL ID you pass the name of the wait event. This time the data comes from DBA_HIST_SYSTEM_EVENT. I typically use this script in two situations:- To check if a particular wait event performs worse when an overall performance problem is reported (usually I'm looking at IO events)
- Illustrate how the implemented change improved the situation.
System Statistics
The last script from this set is awr_stat_trend.sql. It does the same thing with the system statistics collected in DBA_HIST_SYSSTAT as previous scripts did to the performance of SQLs and wait events. The parameters are similar again - the name of the system statistic, days to report and the interval. I usually use the query to check how the redo size or the number of physical reads change over time, but there's huge number of statistics available (638 different statistics in 11.2.0.3) and that's why I'm sure you'll find your own reasons to use this script. [code light="true" language="text" title="SQL> @awr_stat_trend.sql "redo size" 3 4"] TIME STAT_NAME VALUE ------------------- ------------------------- ----------------- 27.10.2013 00:00:00 redo size 1739466208 27.10.2013 04:00:00 redo size 2809857936 27.10.2013 08:00:00 redo size 648511376 27.10.2013 12:00:00 redo size 533287888 27.10.2013 16:00:00 redo size 704832684 27.10.2013 20:00:00 redo size 819854908 28.10.2013 00:00:00 redo size 2226799060 28.10.2013 04:00:00 redo size 3875182764 28.10.2013 08:00:00 redo size 1968024072 28.10.2013 12:00:00 redo size 1125339352 28.10.2013 16:00:00 redo size 1067175300 28.10.2013 20:00:00 redo size 936404908 29.10.2013 00:00:00 redo size 1758952428 29.10.2013 04:00:00 redo size 3949193948 29.10.2013 08:00:00 redo size 1715444632 29.10.2013 12:00:00 redo size 1008385144 29.10.2013 16:00:00 redo size 544946804 17 rows selected. [/code]AWR is a gold mine, but you need the right tools for digging. I hope the scripts will be useful for you too! P.S. You might have noticed the scripts are published on GitHub, let me know if you find any issues using them and perhaps one day you'll find new versions for the script.
Update (4-Nov-2013)
I've added the instance numbers to the outputs in all three scripts. This is how it looks now: [code light="true" language="text" title="SQL> @awr_sqlid_perf_trend.sql 0fxqsqwhkn03b 14 48"] INST TIME EXECUTIONS ELAPSED_TIME_S_1EXEC CPU_TIME_S_1EXEC IOWAIT_S_1EXEC CLWAIT_S_1EXEC APWAIT_S_1EXEC CCWAIT_S_1EXEC ROWS_PROCESSED_1EXEC BUFFER_GETS_1EXEC DISK_READS_1EXEC DIRECT_WRITES_1EXEC ----- ------------------- ----------- -------------------- ---------------- -------------- -------------- -------------- -------------- -------------------- ----------------- ----------------- ------------------- 1 28.10.2013 00:00:00 840 .611 .014 .595 .007 .000 .000 1.000 1085.583 128.724 .000 30.10.2013 00:00:00 1466 .491 .011 .479 .005 .000 .000 1.000 976.001 88.744 .000 01.11.2013 00:00:00 542 .798 .023 .760 .025 .000 .000 1.000 896.978 114.196 .000 03.11.2013 00:00:00 544 .750 .021 .719 .017 .000 .000 1.000 1098.213 134.941 .000 2 28.10.2013 00:00:00 1638 .498 .017 .474 .013 .000 .000 1.001 953.514 96.287 .000 30.10.2013 00:00:00 1014 .745 .022 .712 .019 .000 .000 1.000 1034.249 131.057 .000 01.11.2013 00:00:00 1904 .633 .011 .624 .002 .000 .000 1.000 1045.668 104.568 .000 03.11.2013 00:00:00 810 .602 .017 .581 .010 .000 .000 1.000 929.778 108.998 .000 8 rows selected. [/code]Share this
Previous story
← MSDB – Cleanup is necessary
You May Also Like
These Related Stories
Text index usage within MongoDB
Text index usage within MongoDB
Jul 30, 2018
3
min read
How to decipher oracle Internal datatype storage
How to decipher oracle Internal datatype storage
Dec 11, 2015
9
min read
Magic of "\d" in Vertica
Magic of "\d" in Vertica
Sep 9, 2015
1
min read
No Comments Yet
Let us know what you think