Hi everyone. Today we’re going to talk a bit about a fantastic feature we have in Oracle Database that helps us with performance analysis: AWR.
AWR stands for Automatic Workload Repository, that is, a repository of information about the database workload. The AWR framework collects, processes and maintains performance statistics to make problem detection possible, and it is also the basis for Oracle’s automatic tuning tasks.
These statistics are collected through regular snapshots and stored in the AWR for a defined period. They are based on the moment of the snapshot and can be used to build a report. The values captured by a snapshot represent the changes in each statistic collected over the period.
The statistics collected by the AWR snapshot are stored both in memory and in tables in the SYSAUX tablespace, and can be queried through a number of views.

Snapshots are controlled by the MMON (Manageability Monitor) background process and executed by MMNL (Manageability Monitor Light) according to the defined interval. The default interval is 60 minutes, so a snapshot is taken every 60 minutes. These snapshots are retained for 8 days by default. These settings can be queried through the DBA_HIST_WR_CONTROL view:
SQL> select SNAP_INTERVAL,retention from DBA_HIST_WR_CONTROL;
SNAP_INTERVAL RETENTION
----------------------- ------------------------
+00000 01:00:00.0 +00008 00:00:00.0
We can change these settings with the DBMS_WORKLOAD_REPOSITORY package and the MODIFY_SNAPSHOT_SETTINGS procedure:
SQL> exec DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS( retention => 21600, interval => 30);
PL/SQL procedure successfully completed.
The retention and interval parameters are set in minutes. When you decide to increase the retention settings, always take into account the space needed to store more snapshots over a longer retention period.
Let’s see if the change took effect:
SQL> select SNAP_INTERVAL,retention from DBA_HIST_WR_CONTROL;
SNAP_INTERVAL RETENTION
----------------------- ------------------------
+00000 00:30:00.0 +00015 00:00:00.0
To see the snapshots we can query the DBA_HIST_SNAPSHOT view:
SQL> select * from DBA_HIST_SNAPSHOT order by SNAP_ID;
SNAP_ID DBID INSTANCE_NUMBER STARTUP_TIME BEGIN_INTERVAL_TIME END_INTERVAL_TIME FLUSH_ELAPSED SNAP_LEVEL ERROR_COUNT SNAP_FLAG SNAP_TIMEZONE CON_ID
---------- ---------- --------------- ------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------- ----------- ---------- ------------------------------ ----------
16 1937271711 1 05-JUL-16 09.22.23.000 PM 05-JUL-16 09.22.23.000 PM 05-JUL-16 09.33.11.363 PM +00000 00:00:05.6 1 0 0 -0 03:00:00 1
17 1937271711 1 06-JUL-16 12.16.52.000 PM 06-JUL-16 12.16.52.000 PM 06-JUL-16 12.27.49.416 PM +00000 00:00:05.6 1 0 0 -0 03:00:00 1
18 1937271711 1 06-JUL-16 12.16.52.000 PM 06-JUL-16 12.27.49.416 PM 06-JUL-16 01.00.51.601 PM +00000 00:00:03.4 1 0 0 -0 03:00:00 1
19 1937271711 1 13-JUL-16 07.51.44.000 PM 13-JUL-16 07.51.44.000 PM 13-JUL-16 08.02.38.609 PM +00000 00:00:06.4 1 0 0 -0 03:00:00 1
In this example my snapshots are not hourly, because my VM isn’t always on, but at the end of the article we’ll see what the snapshots look like when I finish writing.
We have the option of taking manual snapshots using the CREATE_SNAPSHOT procedure:
SQL> exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;
PL/SQL procedure successfully completed.
We can also delete them manually with the DROP_SNAPSHOT_RANGE procedure. Let’s query the snapshots and remove a range:
SQL> select * from DBA_HIST_SNAPSHOT order by SNAP_ID;
SNAP_ID DBID INSTANCE_NUMBER STARTUP_TIME BEGIN_INTERVAL_TIME END_INTERVAL_TIME FLUSH_ELAPSED SNAP_LEVEL ERROR_COUNT SNAP_FLAG SNAP_TIMEZONE CON_ID
---------- ---------- --------------- ------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------- ----------- ---------- ------------------------------ ----------
16 1937271711 1 05-JUL-16 09.22.23.000 PM 05-JUL-16 09.22.23.000 PM 05-JUL-16 09.33.11.363 PM +00000 00:00:05.6 1 0 0 -0 03:00:00 1
17 1937271711 1 06-JUL-16 12.16.52.000 PM 06-JUL-16 12.16.52.000 PM 06-JUL-16 12.27.49.416 PM +00000 00:00:05.6 1 0 0 -0 03:00:00 1
18 1937271711 1 06-JUL-16 12.16.52.000 PM 06-JUL-16 12.27.49.416 PM 06-JUL-16 01.00.51.601 PM +00000 00:00:03.4 1 0 0 -0 03:00:00 1
19 1937271711 1 13-JUL-16 07.51.44.000 PM 13-JUL-16 07.51.44.000 PM 13-JUL-16 08.02.38.609 PM +00000 00:00:06.4 1 0 0 -0 03:00:00 1
20 1937271711 1 13-JUL-16 07.51.44.000 PM 13-JUL-16 08.02.38.609 PM 13-JUL-16 08.14.00.718 PM +00000 00:00:02.3 1 0 1 -0 03:00:00 1
SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE (low_snap_id => 16, high_snap_id => 20);
PL/SQL procedure successfully completed.
We can see that all of them were removed:
SQL> select * from DBA_HIST_SNAPSHOT order by SNAP_ID;
no rows selected
If you want to stop collecting AWR information, you can change the statistics_level parameter to BASIC, but you can still trigger snapshots manually with the CREATE_SNAPSHOT procedure. The default is TYPICAL, but if you want more information you can also change it to ALL. These additional statistics are operating system timings and execution plans. We normally set it to ALL when we are deploying a new application and need to debug and tune the code.
Generating an AWR report is easy, but you need at least 2 snapshots. These snapshots must be within the same database operating window, that is, there can’t have been a shutdown between one snapshot and the other.
To generate the report we can run the awrrpt.sql script, or use tools such as Enterprise Manager or SQL Developer. Let’s look at some examples:
SQL> select * from DBA_HIST_SNAPSHOT order by SNAP_ID;
SNAP_ID DBID INSTANCE_NUMBER STARTUP_TIME BEGIN_INTERVAL_TIME END_INTERVAL_TIME FLUSH_ELAPSED SNAP_LEVEL ERROR_COUNT SNAP_FLAG SNAP_TIMEZONE CON_ID
---------- ---------- --------------- ------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------- ----------- ---------- ------------------------------ ----------
21 1937271711 1 13-JUL-16 07.51.44.000 PM 13-JUL-16 08.14.00.718 PM 13-JUL-16 08.30.40.094 PM +00000 00:00:01.9 1 0 0 -0 03:00:00 1
22 1937271711 1 13-JUL-16 07.51.44.000 PM 13-JUL-16 08.30.40.094 PM 13-JUL-16 09.00.42.247 PM +00000 00:00:00.8 1 0 0 -0 03:00:00 1
At the prompts, specify values according to your scenario. In my case I generated an html file, used snap_ids 21 and 22 and set the file name to awr_report_sqlplus:
SQL> @?/rdbms/admin/awrrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
1937271711 LOREDB 1 loredb
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type:
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 1937271711 1 LOREDB loredb loredata-srv
.localdomain
Using 1937271711 for database Id
Using 1 for instance number
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing <return> without
specifying a number lists all completed snapshots.
Enter value for num_days: 1
Listing the last day's Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
loredb LOREDB 21 13 Jul 2016 20:30 1
22 13 Jul 2016 21:00 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 21
Begin Snapshot Id specified: 21
Enter value for end_snap: 22
End Snapshot Id specified: 22
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_21_22.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: awr_report_sqlplus
Using the report name awr_report_sqlplus
Just open the generated file in a browser.
In SQL Developer we can generate the report by following the screens below:



Last but not least, it’s worth remembering the licensing impact when we use AWR. To have the right to query or generate AWR reports, you need a license for Oracle Database Enterprise Edition plus the Diagnostic Pack option. If you use it on Oracle Database Standard Edition, Standard Edition One or Standard Edition Two, know right now that you are violating the license.
Soon I’ll write something about how to analyze an AWR report.
That’s all for today. If you have any questions, just leave a comment.
Regards, and see you next time.
Franky

Comments