You are on page 1of 22

Automatic Workload Repository (AWR) in Oracle Automatic Workload Repository

AWR is very similar to the STATSPACK as well as AWR is a replacement for the STATSPACK utility.(AWR collects and stores database statistics relating to problem detection and tuning ). AWR generates performance data, such as system and session statistics,

Object-usage statistics , time-model statistics , high-load statistics, query statistics and finally stores it in the SYSAUX tablespace. When we create an Oracle database, AWR is automatically installed and enabled. GATHER_STATS_JOB, to collect AWR statistics. This job is created, and enabled automatically when creating a new Oracle 10g database. AWR is to collect database statistics (by default every hour) and this data is maintained for a week and then purged. GATHER_STATS_JOB, to collect AWR statistics every 1 hour. By default, the report will be for the last three days of information. AWR consists of ( Temporary , Persistent ) components. 1) Temporary : Memory statistics (Collection of statistics in the SGA) accessible through V$dynamic views. 2) Persistent : Performance data in the form of regular AWR Snapshots , access via (data dictionary views). AWR scripts are found $ORACLE_HOME/rdbms/admin directory. The MMON process is responsible for collecting the statistics in SGA and saving them to the SYSAUX TABLESPACES. When an instance is shutdown between 2 snapshots , AWR returns error.
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 1 of 22

Automatic Workload Repository (AWR) in Oracle

Disable and Enable the Schedule Job
>>To disable this job using dbms_scheduler.disable >> SQL> Exec dbms_scheduler.disable(’GATHER_STATS_JOB’); >> To enable this job using the dbms_scheduler.enable >> SQL> Exec dbms_scheduler.enable(’GATHER_STATS_JOB’);

AWR Setup
 ALL  BASIC  TYPICAL Basic disables AWR. Typical activates standard level of collection (default option). All same as typical & includes execution plans , timing info from OS. STATISTICS_LEVEL (Parameter) ** Parameter statistics_level maintaining one of the three levels in AWR. ** >> Default value of statistics_level parameter >> SQL> show parameter statistics_level; NAME statistics_level TYPE string VALUE TYPICAL

>> TO change statistics_level parameter to all >> SQL>alter system set statistics_level = all; ** statistics_level = basic , also not recommended to use **
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 2 of 22

Automatic Workload Repository (AWR) in Oracle AWR is used to collect Performance Statistics
 SQL Statistics.  Time Model Statistics  Operating System statistics  Database Object usage statistics.  Wait Statistics -- used to identify performance problems.  ASH statistics from V$ACTIVE_SESSION_HISTRORY  System & Session statistics from the V$SYSSTAT and V$SESSTAT. ASH statistics, representing the history of recent sessions activity. Object statistics determine both access & usage statistics of database segments. Time model statistics based on time usage for activities i.e. indicating the amount of DB time associated with a process from V$SESS_TIME_MODEL & V$SYS_TIME_MODEL views. SQL statements are producing the highest load on the system, based on elapsed time and CPU time .

AWR collects statistics from following V$views :
v$sysstat using for system stats. v$sesstat using for session stats. v$osstat using for operating system stats (avg_busy_ticks, avg_idle_ticks, etc) v$service_stats wait statistics ( db cpu, app wait time, user commits, etc) v$sys_time_model , v$sess_time_model execution time , pl/sql execution time , etc)
EXPLORING AWR by THIYAGU GUNASEKARAN

Time model stats(DB time, java

Page 3 of 22

Automatic Workload Repository (AWR) in Oracle Database Performance stats
** Fall into one of three categories * *  Metrics  Sampled data  Cumulative values ** This topic discuss later on Database Statistics **

AWR Related useful Views :
DBA_HIST_WR_CONTROL DBA_HIST_SNAPSHOT DBA_HIST_BASELINE DBA_HIST_ACTIVE_SESS_HISTORY DBA_HIST_SQL_PLAN DBA_HIST_DATABASE_INSTANCE V$METRIC V$METRICNAME V$METRICGROUP V$METRIC_HISTORY V$ACTIVE_SESSION_HISTORY AWR Settings AWR Snapshot info AWR Baseline info ASH info , Contents of active session SQL Execution plans Database Environment info Metric info Metrics associated with each group All Metric Group Historical Metrics (ASH) Sampled Every Second

 dba_hist_sysstat (System statistics)  dba_hist_waitstat (Wait statistics)  dba_hist_sqlstat (SQL statistics) (Summary & Higher level SQL statistics)

 dba_hist_sql_summary  dba_hist_sql_workarea

 dba_hist_filestatxs (Datafile statistics)  dba_hist_sql_workarea_histogram
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 4 of 22

Automatic Workload Repository (AWR) in Oracle
SNAP SHOTS Snapshots are sets of historical data for specific time periods. By default snapshots are taken every 60 mins. Data in the snapshot interval is analyzed by Automatic Database Diagnostic Monitor (ADDM). We can use DBMS_WORKLOAD_REPOSITORY procedures to manually create, drop, and modify the snapshots but must be granted the DBA role. Each snapshot has a unique ID know as "SNAP_ID". AWR compares snapshots to determine , which SQL statements to capture based on the effect on the system load. DBMS_WORKLOAD_REPOSITORY Package to create or remove snapshots. DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT manual snapshot in the AWR. BASE LINE A baseline is “ Pair of Snapshots ” , difference between two snapshots. In AWR, baselines are identified by range of snapshots preserved for comparison. Baselines are can be used to compare performance against similar periods in the past. Baseline data gathered should include  Application statistics (transaction volumes, response time)  Database statistics  Operating system statistics  Disk I/O statistics  Network statistics
EXPLORING AWR by THIYAGU GUNASEKARAN

procedure creates a

Page 5 of 22

Automatic Workload Repository (AWR) in Oracle Create a Snapshot

SQL>exec dbms_workload_repository.create_snapshot;

Create a Baseline

SQL>exec dbms_workload_repository.create_baseline(start_snap_id => 1240 , end_snap_id=>1244 , baseline_name =>’latest’);

Delete Snapshots

SQL>exec dbms_workload_repository.drop_snapshot_range (low_snap_id => 1077, high_snap_id => 1078);

Delete a Baseline

SQL>exec dbms_workload_repository.drop_baseline(baseline_name=> 'latest’ ,cascade => FALSE); ================================================================ SQL>exec dbms_workload_repository.drop_baseline(baseline_name=> 'latest’ ,cascade => TRUE);

Cascade Options  If cascade is TRUE, it will drop the snapshot in the baseline.  If cascade is FALSE, it will drop the baseline (not the snapshot).

EXPLORING AWR by THIYAGU GUNASEKARAN

Page 6 of 22

Automatic Workload Repository (AWR) in Oracle

>> Displaying list of Snapshots >>
SQL> select snap_id , snap_level , to_char(begin_interval_time, ' dd/mm/yy hh24:mi:ss ') begin from dba_hist_snapshot order by 1;

>> Check Snapshot Interval & Retention Period >>
SQL> select DBID, SNAP_INTERVAL , RETENTION from dba_hist_wr_control; DBID SNAP_INTERVAL RETENTION

2092200073 +00000 01:00:00.0 +00007 00:00:00.0 /*Now I am going to change SNAP INTERVAL DURATION & RETENTION */ ** Snap Interval duration : From 1 hour ** Retention : From 7days
 1day ( 1440  15

MINS mins = 1day ) **

** Retention period (10080 mins =7days)

SQL>exec dbms_workload_repository.modify_snapshot_settings(interval=>15, retention=>1440); PL/SQL procedure successfully completed. >> Check Snapshot Interval & Retention Period after changed >> SQL> select SNAP_INTERVAL , RETENTION from dba_hist_wr_control; SNAP_INTERVAL RETENTION

+00000 00:15:00.0 +00001 00:00:00.0 Snapshot Interval – Snapshot are captured. Snapshots , Baselines are “sets of historical data for a specific timeperiod “ used for performance comparison.
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 7 of 22

Automatic Workload Repository (AWR) in Oracle

Producing AWR report
To run an AWR report, a user must be granted the DBA role. awrrpt.sql &

awrrpti.sql. Both SQL script generates an HTML or text report that displays statistics for a range of snapshot Ids.  awrrpt.sql & awrrpti.sql are exactly same .  awrrpti report allows specific instance to report.  awrrpti.sql asks to enter dbid for particular instance.

SQL>@$ORACLE_HOME/rdbms/admin/awrrpt.sql SQL>@$ORACLE_HOME/rdbms/admin/awrrpti.sql The scripts prompt to enter  Report format (html or text),  Start snapshot_ id,  End snapshot_ id  Report filename. Points to Remember: awrrpt.sql The awrrpt.sql SQL script generates an HTML or text report that displays statistics for a range of snapshot Ids. Report went to $oracle_home\db_1\bin. Begin and End Snapshot Id : Choose from the list displayed Report Name: If leave blank , then it will take default file name.
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 8 of 22

Automatic Workload Repository (AWR) in Oracle
awrrpti.sql The awrrpti.sql script generates an HTML or text report , that displays

statistics for range of snapshot IDs on specified DATABASE & INSTANCE. AWR report for different instances in a RAC database cluster. While running the second script it asks the instance ID to generate the AWR report. Example for to generate AWRRPT (awrrpt.sql) SQL>@$ORACLE_HOME/rdbms/admin/awrrpt.sql First , need to specify whether you want an HTML or a text report. Enter value for report_type: text Specify the number of days for which you want to list snapshot Ids. Enter value for num_days: 3 (is default) After the list displays, prompted for the beginning and ending snapshot Id for the workload repository report. Enter value for begin_snap: 1095 Enter value for end_snap: 1097 Next, accept the default report name or enter a report name. The default name is accepted in the following example: Enter value for report_name: Using the report name awrrpt_1_95_97 The workload repository report is generated. ** If u need specific report name , enter report name “ XXXXXX “ ** ** HTML format is much easier to read/navigate. ** ** HTML format is highly recommended to use this for the output type. **
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 9 of 22

Automatic Workload Repository (AWR) in Oracle
awrddrpt.sql The awrddrpt.sql SQL script generates an HTML or text report that compares detailed performance attributes and configuration settings between two selected time periods. awrsqrpt.sql The awrsqrpt.sql SQL script generates an HTML or text report that displays statistics of a particular SQL statement for a range of snapshot Ids. Run this report to inspect or debug the performance of a SQL statement. awrsqrpi.sql The awrsqrpi.sql SQL script generates an HTML or text report that displays statistics of a particular SQL statement for a range of snapshot Ids on a specified database and instance. Run this report to inspect or debug the performance of a SQL statement on a specific database and instance. awrddrpi.sql The awrddrpi.sql SQL script generates an HTML or text report that compares detailed performance attributes and configuration settings between two selected time periods on a specific database and instance. addmrpt.sql Automatic Database Diagnostic Monitor (ADDM) analyzes the AWR data on a regular basis, then locates the root causes of performance problems, provides recommendations for correcting any problems, and identifies non-problem areas of the system . ADDM can be used to analyze performance issues often saving time and resources reproducing a problem.
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 10 of 22

Automatic Workload Repository (AWR) in Oracle
ashrpt.sql Active Session History (ASH) is a very important feature to analyze sessions in Oracle to troubleshoot transient problems . ASH information is stored within a circular buffer in the SGA . ASH used to identify blocker and waiter identities and their associated transaction identifiers and SQL for a specified duration.

Extract the AWR data
To extract AWR data at the SQL prompt SQL> @$ORACLE_HOME/rdbms/admin/awrextr.sql awrextr.sql script extracts the AWR data for a range of snapshots from the database into a Data Pump export file. Once created, this dump file can be transported to another system where the extracted data can be loaded. To run the awrextr.sql script, need to be connected to the database as the SYS user. LOAD the AWR data To load AWR data at the SQL prompt SQL> @$ORACLE_HOME/rdbms/admin/awrload.sql Once the export dump file is transported to the target system, can load the extracted AWR data using the awrload.sql script. awrload.sql script will first create a staging schema where the snapshot data is transferred from the Data Pump file into the database. The data is then transferred from the staging schema into the appropriate AWR tables. To run the awrload.sql script, need to be connected to the database as the SYS user.
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 11 of 22

Automatic Workload Repository (AWR) in Oracle
SOME POINTS TO NOTE : awrrpt.sql statistics for a range of snapshot Ids. AWR can be called from $ORACLE_HOME/rdbms/admin. AWR outputs based on the events , between 2 snapshots. awrsqrpt.sql statistics of a particular SQL statement for a range of snapshot IDs to inspect performance of a SQL statement. AWR is done through Enterprise Manager ,or DBMS_WORKLOAD_REPOSITORY package. MODIFY_SNAPSHOT_SETTINGS procedure of this package can be used to change the default snapshot settings. Oracle kernel allocates a small distinct portion of the SGA to buffers , that are dedicated to holding session history and other AWR related information. ** In-memory buffer is updated by MMNL and MMON processes ** Collection process involves from the SGA and their transfer to the physical tables located in the workload repository. AWR contains Two types of internal tables AWR is stored in tables owned by ‘SYS’ but physically located on the SYSAUX tablespace. Participate  Metadata Tables  (WRM$_*) ,  Historical Statistics Tables (WRH$_*) Metadata Tables: These are used to control, process, and describe the Workload Repository tables. For example, Oracle uses the metadata tables to determine when to perform snapshots, and what to capture to disk.
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 12 of 22

Automatic Workload Repository (AWR) in Oracle
Historical Statistics Tables: These tables store historical statistical information about the database in the form of snapshots. Each snapshot is a capture of the in–memory database statistics data at a certain point in time.

AWR Performance Tables
AWR table names is prefixed with (wr)

 wrm$ (Metadata tables),  wrh$ (History tables),  wri$ (Advisory tables).
 wrm$ tables store metadata information for the Workload Repository.  The wrh$ tables store historical data or snapshots.  The wri$ tables: These 49 tables store data related to advisory functions.

DOES AWR capture all the SQL which was running in database ?? No How to check whether SQL query captured in AWR ?? Concurrently "n" no of queries issued ... Can't . . . Hundreds, even thousands of queries might have come-and-gone between snapshots. Even at snapshot time, I know of no way to get "missed" SQL statements. . . . Oracle provide a easy method to find out whether sql query captured or not

dbms_workload_repository.awr_sql_report_text
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 13 of 22

Automatic Workload Repository (AWR) in Oracle

>> This ONLY show what WAS captured , not what was lost ! >> SQL> select * from table (dbms_workload_repository.awr_sql_report_text (&v_db_id, &v_inst_num, :b_snap_id, :e_snap_id, '&v_sql_id'));

Query has SQL* Plus ambersand variables & HOST variables so try like this SQL>SELECT * FROM TABLE(dbms_workload_repository.awr_sql_report_text (1692970157, 1, 1230, 1231, 'a01hp0psv0rrh')); MMON captured only top resource consumed queries based on

dbms_workload_repository.modify_snapshot_settings arguments. ** (see dbms_workload_repository.modify_snapshot_settings chapter) **

DBMS_WORKLOAD_REPOSITORY
DBMS_WORKLOAD_REPOSITORY is a PLSQL package allows the DBA to
manage the AWR.

DBMS_WORKLOAD_REPOSITORY package lets to perform operations such as managing snapshots and baselines.
DBMS_WORKLOAD_REPOSITORY .MODIFY_SNAPSHOT_SETTINGS procedure is

used to configure snapshot intervals & AWR data retention in the database. Default value of the snapshot interval is 60 minutes, and the default setting for retention is 10,080 minutes which is seven days.

EXPLORING AWR by THIYAGU GUNASEKARAN

Page 14 of 22

Automatic Workload Repository (AWR) in Oracle
SQL> desc dbms_workload_repository  PROCEDURE CREATE_BASELINE  PROCEDURE DROP_BASELINE  PROCEDURE CREATE_SNAPSHOT  PROCEDURE DROP_SNAPSHOT_RANGE  PROCEDURE MODIFY_SNAPSHOT_SETTINGS ** Desc dbms_workload_repository for additional information ** DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS This procedure controls two aspects of snapshot generation. INTERVAL setting how often snapshots are automatically captured. RETENTION setting how long snapshots are retained in the Workload Repository. SYNTAX DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS (
retention IN NUMBER interval IN NUMBER topnsql IN NUMBER dbid IN NUMBER DEFAULT NULL, DEFAULT NULL, DEFAULT NULL, DEFAULT NULL);

RETENTION time in mins. Retention setting affects how long snapshots are to keep in the Workload Repository. Specified Retention value must be in the range of MIN_RETENTION (1day) to MAX_RETENTION (100 years).
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 15 of 22

Automatic Workload Repository (AWR) in Oracle
INTERVAL Interval setting between each snapshot (unit of mins). Interval setting affects how often snapshots are automatically captured. Specified value must be in the range MIN_INTERVAL (10 minutes) to MAX_INTERVAL (1 year) DBID Database Identifier in AWR for which to modify the snapshot settings. If null specified , the local dbid will be used. TOPNSQL Topnsql is used to specify the number of SQL to collect for each criteria like elapsed time, CPU time, parse calls, shareable memory, version count etc ..
Topnsql is normally set to a small number like 10, can see the most current SQL statements. This SQL information is normally purged after a period of time.

MMON captured top SQL based on below criteria. SQL> exec dbms_workload_repository.modify_snapshot_settings(topnsql => 30); >> No of SQL statements captured depends on statistics_level setting >> If set statistics_level =all, AWR will collect the top 100 SQL statements for
each of the criteria so , total of 1400 SQL statements per snapshot. 14*100 =1400

If set statistics_level=typical, AWR will collect the Top-30 SQL statements for
each SQL category a total of 420 per snapshot. (default leval). 30*14=420.

EXPLORING AWR by THIYAGU GUNASEKARAN

Page 16 of 22

Automatic Workload Repository (AWR) in Oracle
There are 14 criteria in an AWR report & AWR will capture the top-n-SQL for each of following criteria :14 Criteria in AWR:1. Elapsed Time (ms) 2. CPU Time (ms) 3. Executions 4. Buffer Gets 5. Disk Reads 6. Parse Calls 7. Rows 8. User I/O Wait Time (ms) 9. Cluster Wait Time (ms) 10. Application Wait Time (ms) 11. Concurrency Wait Time (ms) 12. Invalidations 13. Version Count 14. Sharable Mem(KB) Note : ORA-13530: SQL> exec dbms_workload_repository.modify_snapshot_settings(topnsql=>10); invalid TOPNSQL 10, must be in the range (30, 50000) View the Repository Tables SQL> select table_name from dba_tables where tablespace_name = ‘SYSAUX’ and substr(table_name, 1,2) = ‘WR’ and rownum <= 20 order by 1;
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 17 of 22

Automatic Workload Repository (AWR) in Oracle
FINAL TIPS :  Set the retention to 60 or 90 days.  Review the reports at least once a week  Look into ASH also for more information  Watch the size of the SYSAUX Tablespace.  Don't change the snapshot interval, It is a good balance between too often and too few. All DBA_HIST views are confusing , Look at these general categories:  File statistics  SQL statistics  Undo Statistics  Segment Statistics  Recovery Statistics  Time-model statistics  Concurrency statistics  Instance tuning statistics  General System statistics Points to keep in mind :V$STATISTICS_LEVEL view displays information about the status of the statistics or advisories controlled by the STATISTICS_LEVEL parameter. IF STATISTICS_LEVEL =ALL, additional statistics are added to the set of statistics collected with the TYPICAL setting. They are Timed OS statistics and plan execution statistics.

EXPLORING AWR by THIYAGU GUNASEKARAN

Page 18 of 22

Automatic Workload Repository (AWR) in Oracle
Oracle captures every SQL ? ABSOLUTELY NO. Capturing every SQL might be too heavy. Oracle only captures part of the SQLs which are considered to be meaingful workloads. Actual configuration is controlled by following procedure. dbms_workload_repository.modify_snapshot_settings.

Important AWR Tables
DBA_HIST_SNAPSHOT  PK SNAP_ID DBID, INSTANCE_NUMBER BEGIN_INTERVAL_TIME END_INTERVAL_TIME DBA_HIST_SQLSTAT  PK SNAP_ID SQL_ID, PLAN_HASH_VALUE (DBID, INSTANCE_NUMBER)  BASIC STATS Executions, Gets, Reads  TIME CPU, Elapsed  WAIT TIME: IO, Concurrency, App  Time in microseconds
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 19 of 22

Automatic Workload Repository (AWR) in Oracle

DBA_HIST_SYSSTAT  PK SNAP_ID STAT_ID (DBID, INSTANCE_NUMBER)  AWR snapshots of V$SYSSTAT  Includes STAT_NAME (almost 400!)  Does NOT include deltas, you need to calculate these yourself  Watch out for stat counter resets (bounces)  “DB time” in units of centiseconds  Use as basis of comparison DBA_HIST_SQLTEXT  PK SQL_ID DBID  No SNAP_ID, INSTANCE_NUMBER  Preserves SQL_TEXT even when found nowhere else DBA_HIST_SYSTEM_EVENT  PK SNAP_ID EVENT_ID (DBID, INSTANCE_NUMBER)  AWR snapshots of V$SYSTEM_EVENT  Includes EVENT_NAME (almost 900!)  Does NOT equal sum of ASH sampling  Time is clearly in units of microseconds
EXPLORING AWR by THIYAGU GUNASEKARAN

Page 20 of 22

Automatic Workload Repository (AWR) in Oracle
DBA_HIST_SEG_STAT_OBJ  PK OBJ#, DATAOBJ# (DBID)  Object details (name, owner, type, tablespace)  Several segment types: Table, Table Partition Index, Index Partition , LOB

Performance Tuning Questions
1. How to tune a SQL Queries ? 2. What is a driving table in a SQL query ? 3. How do you keep the store PLSQL blocks in memory. 4. How would you begin to troubleshoot an ORA-3113 error? 5. How to get Statspack reports and what you will look into main events 6. You’re getting high “busy buffer waits” – how to find what’s causing it? 7. A User/Developer calls in saying that their process is running very slow How would you go about troubleshooting the issue? 8. An automatic job running via DBMS_JOB has failed. Knowing only that “it’s failed”, how do you approach troubleshooting this issue? 9. Database is hung. Old and new user connections alike hang on impact. What do you do? Your SYS SQLPLUS session IS able to connect ? 10.What would you use to improve performance on an insert statement that places millions of rows into that table? 11.You’re running a DML statement and you get an error saying the rollback segment cannot extend. how do to fix this ?

EXPLORING AWR by THIYAGU GUNASEKARAN

Page 21 of 22

Automatic Workload Repository (AWR) in Oracle

EXPLORING AWR by THIYAGU GUNASEKARAN

Page 22 of 22