Awr New
Awr New
Awr New
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
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 .
Page 3 of 22
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
Page 4 of 22
procedure creates a
Page 5 of 22
SQL>exec dbms_workload_repository.create_snapshot;
Create a Baseline
Delete Snapshots
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).
Page 6 of 22
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
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
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
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
Page 10 of 22
Page 11 of 22
Page 12 of 22
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
>> 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
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.
Page 14 of 22
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
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.
Page 16 of 22
Page 17 of 22
Page 18 of 22
Page 19 of 22
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
Page 21 of 22
Page 22 of 22