6 Gathering Database Statistics

This chapter describes how to gather database statistics for Oracle Database and contains the following topics:

6.1 About Gathering Database Statistics

Oracle Database automatically persists the cumulative and delta values for most of the statistics at all levels (except the session level) in the Automatic Workload Repository (AWR). This process is repeated on a regular time period and the results are captured in an AWR snapshot. The delta values captured by the snapshot represent the changes for each statistic over the time period.

A statistical baseline is a collection of statistic rates usually taken over a time period when the system is performing well at an optimal level. Use statistical baselines to diagnose performance problems by comparing statistics captured in a baseline to those captured during a period of poor performance. This enables you to identify specific statistics that may have increased significantly and could be the cause of the problem. AWR supports the capture of baseline data by enabling you to specify and preserve a pair or range of AWR snapshots as a baseline.

A metric is typically the rate of change in a cumulative statistic. You can measure this rate against a variety of units, including time, transactions, or database calls. For example, the number database calls per second is a metric. Metric values are exposed in some V$ views, where the values are the averages over a fairly small time interval, typically 60 seconds. A history of recent metric values is available through V$ views, and some data is also persisted by AWR snapshots.

The following sections describe various Oracle Database features that enable you to more effectively gather database statistics:

Note:

Use of AWR features described in this chapter requires licensing of the Oracle Diagnostic Pack.

Note:

Data visibility and privilege requirements may differ when using AWR features with pluggable databases (PDBs). For information about how manageability features—including AWR features—work in a multitenant container database (CDB), see Oracle Database Administrator's Guide.

6.1.1 Automatic Workload Repository

AWR collects, processes, and maintains performance statistics for problem detection and self-tuning purposes. This gathered data is stored both in memory and in the database, and is displayed in both reports and views.

The statistics collected and processed by AWR include:

  • Object statistics that determine both access and usage statistics of database segments

  • Time model statistics based on time usage for activities, displayed in the V$SYS_TIME_MODEL and V$SESS_TIME_MODEL views

  • Some of the system and session statistics collected in the V$SYSSTAT and V$SESSTAT views

  • SQL statements that are producing the highest load on the system, based on criteria such as elapsed time and CPU time

  • Active Session History (ASH) statistics, representing the history of recent sessions activity

See Also:

6.1.2 Snapshots

Snapshots are sets of historical data for specific time periods that are used for performance comparisons by Automatic Database Diagnostic Monitor (ADDM). By default, Oracle Database automatically generates snapshots of the performance data once every hour and retains the statistics in AWR for 8 days. You can also manually create snapshots or change the snapshot retention period, but it is usually not necessary.

AWR compares the difference between snapshots to determine which SQL statements to capture based on the effect on the system load. This reduces the number of SQL statements that must be captured over time. After the snapshots are created, ADDM analyzes the data captured in the snapshots to perform its performance analysis.

See Also:

"Managing Snapshots" for information about managing snapshots

6.1.3 Baselines

A baseline is a set of snapshots from a specific time period that is preserved for comparison with other snapshots when a performance problem occurs. The snapshots contained in a baseline are excluded from the automatic AWR purging process and are retained indefinitely.

There are several types of available baselines:

6.1.3.1 Fixed Baselines

A fixed baseline corresponds to a fixed, contiguous time period in the past that you specify. Before creating a fixed baseline, carefully consider the time period you choose as a baseline, because the baseline should represent the system operating at an optimal level. In the future, you can compare the baseline with other baselines or snapshots captured during periods of poor performance to analyze performance degradation over time.

See Also:

"Managing Baselines" for information about managing fixed baselines

6.1.3.2 Moving Window Baselines

A moving window baseline corresponds to all AWR data that exists within the AWR retention period. This is useful when using adaptive thresholds because the database can use AWR data in the entire AWR retention period to compute metric threshold values.

Oracle Database automatically maintains a system-defined moving window baseline. The default window size for the system-defined moving window baseline is the current AWR retention period, which by default is 8 days. If you are planning to use adaptive thresholds, then consider using a larger moving window—such as 30 days—to accurately compute threshold values. You can resize the moving window baseline by changing the number of days in the moving window to a value that is equal to or less than the number of days in the AWR retention period. Therefore, to increase the size of a moving window, you must first increase the AWR retention period accordingly.

See Also:

"Resizing the Default Moving Window Baseline" for information about resizing a moving window baseline

6.1.3.3 Baseline Templates

Baseline templates enable you to create baselines for a contiguous time period in the future. There are two types of baseline templates:

See Also:

"Managing Baseline Templates" for information about managing baseline templates
6.1.3.3.1 Single Baseline Templates

Use a single baseline template to create a baseline for a single contiguous time period in the future. This is useful if you know beforehand of a time period that you intend to capture in the future. For example, you may want to capture AWR data during a system test that is scheduled for the upcoming weekend. In this case, you can create a single baseline template to automatically capture the time period when the test occurs.

6.1.3.3.2 Repeating Baseline Templates

Use a repeating baseline template to create and drop baselines based on a repeating time schedule. This is useful if you want Oracle Database to automatically capture a contiguous time period on an ongoing basis. For example, you may want to capture AWR data during every Monday morning for a month. In this case, you can create a repeating baseline template to automatically create baselines on a repeating schedule for every Monday, and automatically remove older baselines after a specified expiration interval, such as one month.

6.1.4 Space Consumption

The space consumed by AWR is determined by several factors:

  • Number of active sessions in the database at any given time

  • Snapshot interval

    The snapshot interval determines the frequency at which snapshots are captured. A smaller snapshot interval increases the frequency, which increases the volume of data collected by AWR.

  • Historical data retention period

    The retention period determines how long this data is retained before being purged. A longer retention period increases the space consumed by AWR.

By default, Oracle Database captures snapshots once every hour and retains them in the database for 8 days. With these default settings, a typical system with an average of 10 concurrent active sessions can require approximately 200 to 300 MB of space for its AWR data.

To reduce AWR space consumption, increase the snapshot interval and reduce the retention period. When reducing the retention period, note that several Oracle Database self-managing features depend on AWR data for proper functioning. Not having enough data can affect the validity and accuracy of these components and features, including:

  • Automatic Database Diagnostic Monitor (ADDM)

  • SQL Tuning Advisor

  • Undo Advisor

  • Segment Advisor

If possible, Oracle recommends that you set the AWR retention period large enough to capture at least one complete workload cycle. If your system experiences weekly workload cycles—such as OLTP workload during weekdays and batch jobs during the weekend—then you do not need to change the default AWR retention period of 8 days. However, if your system is subjected to a monthly peak load during month-end book closing, then you may need to set the retention period to one month.

Under exceptional circumstances, you can disable automatic snapshot collection by setting the snapshot interval to 0. Under this condition, the automatic collection of the workload and statistical data is stopped, and most of the Oracle Database self-management functionality is not operational. In addition, you cannot manually create snapshots. For this reason, Oracle strongly recommends against disabling automatic snapshot collection.

See Also:

"Modifying Snapshot Settings" for information about changing the default values for the snapshot interval and retention period

6.1.5 Adaptive Thresholds

Adaptive thresholds enable you to monitor and detect performance issues, while minimizing administrative overhead. Adaptive thresholds automatically set warning and critical alert thresholds for some system metrics using statistics derived from metric values captured in the moving window baseline. The statistics for these thresholds are recomputed weekly and might result in new thresholds as system performance evolves over time. Additionally, adaptive thresholds can compute different thresholds values for different times of the day or week based on periodic workload patterns.

For example, many databases support an online transaction processing (OLTP) workload during the day and batch processing at night. The performance metric for response time per transaction can be useful for detecting degradation in OLTP performance during the day. However, a useful OLTP threshold value is usually too low for batch workloads, where long-running transactions might be common. As a result, threshold values appropriate to OLTP might trigger frequent false performance alerts during batch processing. Adaptive thresholds can detect such a workload pattern and automatically set different threshold values for daytime and nighttime.

There are two types of adaptive thresholds:

6.1.5.1 Percentage of Maximum Thresholds

The threshold value for percentage of maximum thresholds is computed as a percentage multiple of the maximum value observed for the data in the moving window baseline.

Percentage of maximum thresholds are most useful when a system is sized for peak workloads, and you want to be alerted when the current workload volume approaches or exceeds previous high values. Metrics that have an unknown but definite limiting value are prime candidates for these settings. For example, the redo generated per second metric is typically a good candidate for a percentage of maximum threshold.

6.1.5.2 Significance Level Thresholds

The threshold value for significance level thresholds is set to a statistical percentile that represents how unusual it is to observe values above the threshold value based the data in the moving window baseline.

Significance level thresholds are most useful for metrics that exhibit statistically stable behavior when the system is operating normally, but might vary over a wide range when the system is performing poorly. For example, the response time per transaction metric should be stable for a well-tuned OLTP system, but may fluctuate widely when performance issues arise. Significance level thresholds are meant to generate alerts when conditions produce both unusual metric values and unusual system performance.

Significance level thresholds can be set to one of the following levels:

  • High (.95)

    Only 5 in 100 observations are expected to exceed this value.

  • Very High (.99)

    Only 1 in 100 observations are expected to exceed this value.

  • Severe (.999)

    Only 1 in 1,000 observations are expected to exceed this value.

  • Extreme (.9999)

    Only 1 in 10,000 observations are expected to exceed this value.

When you specify a significance level threshold, Oracle Database performs an internal calculation to set the threshold value. In some cases, Oracle Database cannot establish the threshold value at higher significance levels using the data in the baseline, and the significance level threshold is not set.

If you specified a Severe (.999) or Extreme (.9999) significance level threshold and are not receiving alerts as expected, try setting the significance level threshold to a lower value, such as Very High (.99) or High (.95). Alternatively, consider using a percentage of maximum threshold instead. If you change the threshold and find that you are receiving too many alerts, try increasing the number of occurrences to trigger an alert.

Note:

The primary interface for managing baseline metrics is Oracle Enterprise Manager. To create an adaptive threshold for a baseline metric, use Oracle Enterprise Manager, as described in Oracle Database 2 Day + Performance Tuning Guide.

See Also:

6.2 Managing the Automatic Workload Repository

This section describes how to manage AWR features of Oracle Database and contains the following topics:

See Also:

"Automatic Workload Repository" for a description of AWR

6.2.1 Enabling the Automatic Workload Repository

Gathering database statistics using AWR is enabled by default and is controlled by the STATISTICS_LEVEL initialization parameter.

To enable statistics gathering by AWR: 

  • Set the STATISTICS_LEVEL parameter to TYPICAL or ALL.

    The default setting for this parameter is TYPICAL.

Setting STATISTICS_LEVEL to BASIC disables many Oracle Database features, including AWR, and is not recommended. If STATISTICS_LEVEL is set to BASIC, you can still manually capture AWR statistics using the DBMS_WORKLOAD_REPOSITORY package. However, because in-memory collection of many system statistics—such as segments statistics and memory advisor information—will be disabled, the statistics captured in these snapshots may not be complete.

See Also:

Oracle Database Reference for information about the STATISTICS_LEVEL initialization parameter

6.2.2 Managing Snapshots

By default, Oracle Database generates snapshots once every hour, and retains the statistics in the workload repository for 8 days. When necessary, you can manually create or drop snapshots and modify snapshot settings.

This section describes how to manage snapshots and contains the following topics:

See Also:

"Snapshots" for information about snapshots

6.2.2.1 User Interfaces for Managing Snapshots

The primary interface for managing snapshots is Oracle Enterprise Manager. Whenever possible, you should manage snapshots using Oracle Enterprise Manager.

If Oracle Enterprise Manager is unavailable, then manage snapshots using the DBMS_WORKLOAD_REPOSITORY package in the command-line interface. The DBA role is required to invoke the DBMS_WORKLOAD_REPOSITORY procedures.

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.2.2 Creating Snapshots

By default, Oracle Database automatically generates snapshots once every hour. However, you may want to manually create snapshots to capture statistics at times different from those of the automatically generated snapshots.

This section describes how to create snapshots and contains the following topics:

6.2.2.2.1 Creating Snapshots Using the Command-Line Interface

To manually create snapshots, use the CREATE_SNAPSHOT procedure.

Example 6-1 shows a CREATE_SNAPSHOT procedure call.

Example 6-1 Using the CREATE_SNAPSHOT Procedure

BEGIN
  DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();
END;
/

In this example, a snapshot is created immediately on the local database instance with the flush level specified to the default flush level of TYPICAL. To view information about the newly created snapshot (and any existing snapshots), use the DBA_HIST_SNAPSHOT view.

See Also:

6.2.2.3 Dropping Snapshots

By default, Oracle Database automatically purges snapshots that have been stored in AWR for over 8 days. However, you may want to manually drop a range of snapshots to free up space.

This section describes how to drop snapshots and contains the following topics:

6.2.2.3.1 Dropping Snapshots Using the Command-Line Interface

To manually drop a range of snapshots, use the DROP_SNAPSHOT_RANGE procedure.

Example 6-2 shows a DROP_SNAPSHOT_RANGE procedure call.

Example 6-2 Using the DROP_SNAPSHOT_RANGE Procedure

BEGIN
  DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE (low_snap_id => 22, 
                           high_snap_id => 32, dbid => 3310949047);
END;
/

In the example, snapshots with snapshot IDs ranging from 22 to 32 are dropped immediately from the database instance with the database identifier of 3310949047. Any ASH data that were captured during this snapshot range are also purged.

Tip:

To determine which snapshots to drop, use the DBA_HIST_SNAPSHOT view to review the existing snapshots

See Also:

6.2.2.4 Modifying Snapshot Settings

You can adjust the interval, retention, and captured Top SQL of snapshot generation for a specified database ID, but note that this can affect the precision of the Oracle Database diagnostic tools.

This section describes how to modify snapshot settings and contains the following topics:

6.2.2.4.1 Modifying Snapshot Settings Using the Command-Line Interface

You can modify various snapshot settings using the MODIFY_SNAPSHOT_SETTINGS procedure:

  • The INTERVAL setting affects how often the database automatically generates snapshots.

  • The RETENTION setting affects how long the database stores snapshots in AWR.

  • The TOPNSQL setting affects the number of Top SQL to flush for each SQL criteria (Elapsed Time, CPU Time, Parse Calls, sharable Memory, and Version Count).

    The value for this setting is not affected by the statistics/flush level and overrides the system default behavior for AWR SQL collection. It is possible to set the value for this setting to MAXIMUM to capture the complete set of SQL in the shared SQL area, though doing so (or by setting the value to a very high number) may lead to possible space and performance issues because there will be more data to collect and store.

To modify the settings, use the MODIFY_SNAPSHOT_SETTINGS procedure, as shown in the following example.

Example 6-3 shows a MODIFY_SNAPSHOT_SETTINGS procedure call.

Example 6-3 Using the MODIFY_SNAPSHOT_SETTINGS Procedure

BEGIN
  DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS( retention => 43200, 
                 interval => 30, topnsql => 100, dbid => 3310949047);
END;
/

In this example, the snapshot settings for the database with the database identifier of 3310949047 are modified as follows:

  • The retention period is specified as 43200 minutes (30 days).

  • The interval between each snapshot is specified as 30 minutes.

  • The number of Top SQL to flush for each SQL criteria is specified as 100.

To verify the current settings for your database, use the DBA_HIST_WR_CONTROL view.

See Also:

6.2.3 Managing Baselines

By default, Oracle Database automatically maintains a system-defined moving window baseline. When necessary, you can manually create, drop, or rename a baseline and view the baseline threshold settings. Additionally, you can manually resize the window size of the moving window baseline.

This section describes how to manage baselines and contains the following topics:

See Also:

"Baselines" for information about baselines

6.2.3.1 User Interface for Managing Baselines

The primary interface for managing baselines is Oracle Enterprise Manager. Whenever possible, manage baselines using Oracle Enterprise Manager.

If Oracle Enterprise Manager is unavailable, then manage baselines using the DBMS_WORKLOAD_REPOSITORY package in the command-line interface. The DBA role is required to invoke the DBMS_WORKLOAD_REPOSITORY procedures.

See Also:

6.2.3.2 Creating a Baseline

By default, Oracle Database automatically maintains a system-defined moving window baseline. However, you may want to manually create a fixed baseline that represents the system operating at an optimal level, so you can compare it with other baselines or snapshots captured during periods of poor performance.

This section describes how to create a baseline using an existing range of snapshots and contains the following topics:

6.2.3.2.1 Creating a Baseline Using the Command-Line Interface

To create baselines, use the CREATE_BASELINE procedure.

Example 6-4 shows a CREATE_BASELINE procedure call.

Example 6-4 Using the CREATE_BASELINE Procedure

BEGIN
    DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE (start_snap_id => 270, 
                   end_snap_id => 280, baseline_name => 'peak baseline', 
                   dbid => 3310949047, expiration => 30);
END;
/

In this example, a baseline is created on the database instance with the database identifier of 3310949047 with the following settings:

  • The start snapshot sequence number is 270.

  • The end snapshot sequence number is 280.

  • The name of baseline is peak baseline.

  • The expiration of the baseline is 30 days.

Oracle Database automatically assigns a unique baseline ID to the new baseline when the baseline is created.

Tip:

To determine the range of snapshots to include in a baseline, use the DBA_HIST_SNAPSHOT view to review the existing snapshots

See Also:

6.2.3.3 Dropping a Baseline

To conserve disk space, consider periodically dropping a baseline that is no longer being used. The snapshots associated with a baseline are retained indefinitely until you explicitly drop the baseline or the baseline has expired.

This section describes how to drop an existing baseline and contains the following topics:

6.2.3.3.1 Dropping a Baseline Using the Command-Line Interface

To drop a baseline, use the DROP_BASELINE procedure.

Example 6-5 shows a DROP_BASELINE procedure call.

Example 6-5 Using the DROP_BASELINE Procedure

BEGIN
  DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE (baseline_name => 'peak baseline',
                  cascade => FALSE, dbid => 3310949047);
END;
/

In the example, the baseline peak baseline is dropped from the database instance with the database identifier of 3310949047 and the associated snapshots are preserved.

Tip:

To determine which baseline to drop, use the DBA_HIST_BASELINE view to review the existing baselines

Tip:

To drop the associated snapshots along with the baseline, set the cascade parameter to TRUE

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.3.4 Renaming a Baseline

This section describes how to rename a baseline and contains the following topics:

6.2.3.4.1 Renaming a Baseline Using the Command-Line Interface

To rename a baseline, use the RENAME_BASELINE procedure.

Example 6-6 shows a RENAME_BASELINE procedure call.

Example 6-6 Using the RENAME_BASELINE Procedure

BEGIN
    DBMS_WORKLOAD_REPOSITORY.RENAME_BASELINE (
                   old_baseline_name => 'peak baseline', 
                   new_baseline_name => 'peak mondays', 
                   dbid => 3310949047);
END;
/

In this example, the name of the baseline on the database instance with the database identifier of 3310949047 is renamed from peak baseline to peak mondays.

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.3.5 Displaying Baseline Metrics

When used with adaptive thresholds, a baseline contains AWR data that the database can use to compute metric threshold values. This section describes how to display metric threshold settings during the time period captured in a baseline and contains the following topics:

See Also:

"Adaptive Thresholds" for information about baseline metric thresholds
6.2.3.5.1 Displaying Baseline Metrics Using the Command-Line Interface

To display the summary statistics for metric values in a baseline period, use the SELECT_BASELINE_METRICS function:

DBMS_WORKLOAD_REPOSITORY.SELECT_BASELINE_METRICS (
    baseline_name IN VARCHAR2,
             dbid IN NUMBER DEFAULT NULL,
     instance_num IN NUMBER DEFAULT NULL)
RETURN awr_baseline_metric_type_table PIPELINED;

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.3.6 Resizing the Default Moving Window Baseline

By default, Oracle Database automatically maintains a system-defined moving window baseline. The default window size for the system-defined moving window baseline is the current AWR retention period, which by default is 8 days. In certain circumstances, you may want to modify the window size of the default moving window baseline, such as increasing its size to more accurately compute threshold values for adaptive thresholds.

This section describes how to resize the window size of the default moving window baseline and contains the following topics:

See Also:

"Moving Window Baselines" for information about moving window baselines
6.2.3.6.1 Resizing the Default Moving Window Using the Command-Line Interface

To modify the window size of the default moving window baseline, use the MODIFY_BASELINE_WINDOW_SIZE procedure.

Example 6-7 shows a MODIFY_BASELINE_WINDOW_SIZE procedure call.

Example 6-7 Using the MODIFY_BASELINE_WINDOW_SIZE Procedure

BEGIN
    DBMS_WORKLOAD_REPOSITORY.MODIFY_BASELINE_WINDOW_SIZE (
                   window_size => 30, 
                   dbid => 3310949047);
END;
/

In this example, the default moving window is resized to 30 days on the database instance with the database identifier of 3310949047.

Note:

The window size must be set to a value that is equal to or less than the value of the AWR retention setting. To set a window size that is greater than the current AWR retention period, you must first increase the value of the retention parameter, as described in "Modifying Snapshot Settings".

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.4 Managing Baseline Templates

Baseline templates enable you to automatically create baselines to capture specified time periods in the future. This section describes how to manage baseline templates and contains the following topics:

See Also:

"Baseline Templates" for information about baseline templates

6.2.4.1 User Interfaces for Managing Baseline Templates

The primary interface for managing baseline templates is Oracle Enterprise Manager. Whenever possible, manage baseline templates using Oracle Enterprise Manager.

If Oracle Enterprise Manager is unavailable, then manage baseline templates using the DBMS_WORKLOAD_REPOSITORY package in the command-line interface. The DBA role is required to invoke the DBMS_WORKLOAD_REPOSITORY procedures.

See Also:

Oracle Database 2 Day + Performance Tuning Guide for more information about managing baseline templates using Oracle Enterprise Manager

6.2.4.2 Creating a Single Baseline Template

You can use a single baseline template to create a baseline during a single, fixed time interval in the future. For example, you can create a single baseline template to generate a baseline that is captured on April 2, 2012 from 5:00 p.m. to 8:00 p.m.

This section describes how to create a single baseline template and contains the following topics:

6.2.4.2.1 Creating a Single Baseline Template Using the Command-Line Interface

To create a single baseline template, use the CREATE_BASELINE_TEMPLATE procedure.

Example 6-8 shows a CREATE_BASELINE_TEMPLATE procedure call.

Example 6-8 Using the CREATE_BASELINE_TEMPLATE Procedure

BEGIN
    DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE_TEMPLATE (
                   start_time => '2012-04-02 17:00:00 PST', 
                   end_time => '2012-04-02 20:00:00 PST', 
                   baseline_name => 'baseline_120402', 
                   template_name => 'template_120402', expiration => 30, 
                   dbid => 3310949047);
END;
/

In this example, a baseline template named template_120402 is created that will generate a baseline named baseline_120402 for the time period from 5:00 p.m. to 8:00 p.m. on April 2, 2012 on the database with a database ID of 3310949047. The baseline will expire after 30 days.

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.4.3 Creating a Repeating Baseline Template

You can use a repeating baseline template to automatically create baselines that repeat during a particular time interval over a specific period in the future. For example, you can create a repeating baseline template to generate a baseline that repeats every Monday from 5:00 p.m. to 8:00 p.m. for the year 2012.

This section describes how to create a repeating baseline template and contains the following topics:

6.2.4.3.1 Creating a Repeating Baseline Template Using the Command-Line Interface

To create a repeating baseline template, use the CREATE_BASELINE_TEMPLATE procedure.

Example 6-9 shows a CREATE_BASELINE_TEMPLATE procedure call.

Example 6-9 Using the CREATE_BASELINE_TEMPLATE Procedure

BEGIN
    DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE_TEMPLATE (
                   day_of_week => 'monday', hour_in_day => 17,
                   duration => 3, expiration => 30,
                   start_time => '2012-04-02 17:00:00 PST', 
                   end_time => '2012-12-31 20:00:00 PST', 
                   baseline_name_prefix => 'baseline_2012_mondays_', 
                   template_name => 'template_2012_mondays',
                   dbid => 3310949047);
END;
/

In this example, a baseline template named template_2012_mondays is created that will generate a baseline on every Monday from 5:00 p.m. to 8:00 p.m. beginning on April 2, 2012 at 5:00 p.m. and ending on December 31, 2012 at 8:00 p.m. on the database with a database ID of 3310949047. Each of the baselines will be created with a baseline name with the prefix baseline_2012_mondays_ and will expire after 30 days.

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.4.4 Dropping a Baseline Template

Periodically, you may want to remove baselines templates that are no longer used to conserve disk space.

This section describes how to drop an existing baseline template and contains the following topics:

6.2.4.4.1 Dropping a Baseline Template Using the Command-Line Interface

To drop a baseline template, use the DROP_BASELINE_TEMPLATE procedure.

Example 6-10 shows a DROP_BASELINE_TEMPLATE procedure call.

Example 6-10 Using the DROP_BASELINE_TEMPLATE Procedure

BEGIN
  DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE_TEMPLATE (
                   template_name => 'template_2012_mondays',
                   dbid => 3310949047);
END;
/

In this example, the baseline template named template_2012_mondays is dropped from the database instance with the database identifier of 3310949047.

Tip:

To determine which baseline template to drop, use the DBA_HIST_BASELINE_TEMPLATE view to review the existing baseline templates

See Also:

Oracle Database PL/SQL Packages and Types Reference for information about the DBMS_WORKLOAD_REPOSITORY package

6.2.5 Transporting Automatic Workload Repository Data

Oracle Database enables you to transport AWR data between systems. This is useful in cases where you want to use a separate system to perform analysis of AWR data. To transport AWR data, first extract the data from the database on the source system, and then load the data into the database on the target system.

This section contains the following topics:

6.2.5.1 Extracting AWR Data

The awrextr.sql script extracts AWR data for a range of snapshots from the database into a Data Pump export file. After it is created, you can transport this dump file to another database where you can load the extracted data. To run the awrextr.sql script, you must be connected to the database as the SYS user.

To extract AWR data: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrextr.sql
    

    A list of the databases in the AWR schema is displayed.

  2. Specify the database from which AWR data will be extracted:

    Enter value for db_id: 1377863381
    

    In this example, the database with the database identifier of 1377863381 is selected.

  3. Specify the number of days for which you want to list snapshot IDs.

    Enter value for num_days: 2
    

    A list of existing snapshots for the specified time range is displayed. In this example, snapshots captured in the last 2 days are displayed.

  4. Define the range of snapshots for which AWR data will be extracted by specifying a beginning and ending snapshot ID:

    Enter value for begin_snap: 30
    Enter value for end_snap: 40
    

    In this example, the snapshot with a snapshot ID of 30 is selected as the beginning snapshot, and the snapshot with a snapshot ID of 40 is selected as the ending snapshot.

    A list of directory objects is displayed.

  5. Specify the directory object pointing to the directory where the export dump file will be stored:

    Enter value for directory_name: DATA_PUMP_DIR
    

    In this example, the directory object DATA_PUMP_DIR is selected.

  6. Specify a prefix for the name of the export dump file (the .dmp suffix will be automatically appended):

    Enter value for file_name: awrdata_30_40
    

    In this example, an export dump file named awrdata_30_40 will be created in the directory corresponding to the directory object you specified:

    Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
    C:\ORACLE\PRODUCT\12.1.0.1\DB_1\RDBMS\LOG\AWRDATA_30_40.DMP
    Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 08:58:20
    

    Depending on the amount of AWR data that must be extracted, the AWR extract operation may take a while to complete. After the dump file is created, you can use Data Pump to transport the file to another system.

See Also:

Oracle Database Utilities for information about using Data Pump

6.2.5.2 Loading AWR Data

After the export dump file is transported to the target system, load the extracted AWR data using the awrload.sql script. The 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, you must be connected to the database as the SYS user.

To load AWR data: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrload.sql
    

    A list of directory objects is displayed.

  2. Specify the directory object pointing to the directory where the export dump file is located:

    Enter value for directory_name: DATA_PUMP_DIR
    

    In this example, the directory object DATA_PUMP_DIR is selected.

  3. Specify a prefix for the name of the export dump file (the .dmp suffix will be automatically appended):

    Enter value for file_name: awrdata_30_40
    

    In this example, the export dump file named awrdata_30_40 is selected.

  4. Specify the name of the staging schema where AWR data will be loaded:

    Enter value for schema_name: AWR_STAGE
    

    In this example, a staging schema named AWR_STAGE will be created where AWR data will be loaded.

  5. Specify the default tablespace for the staging schema:

    Enter value for default_tablespace: SYSAUX
    

    In this example, the SYSAUX tablespace is selected.

  6. Specify the temporary tablespace for the staging schema:

    Enter value for temporary_tablespace: TEMP
    

    In this example, the TEMP tablespace is selected.

  7. A staging schema named AWR_STAGE will be created where AWR data will be loaded. After AWR data is loaded into the AWR_STAGE schema, the data will be transferred into AWR tables in the SYS schema:

    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Completed 113 CONSTRAINT objects in 11 seconds
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
    Completed 1 REF_CONSTRAINT objects in 1 seconds
    Job "SYS"."SYS_IMPORT_FULL_03" successfully completed at 09:29:30
    ... Dropping AWR_STAGE user
    End of AWR Load
    

    Depending on the amount of AWR data that must be loaded, the AWR load operation may take a while to complete. After AWR data is loaded, the staging schema will be dropped automatically.

6.2.6 Using Automatic Workload Repository Views

Typically, you would view AWR data through Oracle Enterprise Manager or AWR reports. However, you can also view historical data stored in AWR using the following DBA_HIST views:

  • DBA_HIST_ACTIVE_SESS_HISTORY displays the history of the contents of the in-memory active session history for recent system activity.

  • DBA_HIST_BASELINE displays information about the baselines captured on the system, such as the time range of each baseline and the baseline type.

  • DBA_HIST_BASELINE_DETAILS displays details about a specific baseline.

  • DBA_HIST_BASELINE_TEMPLATE displays information about the baseline templates used by the system to generate baselines.

  • DBA_HIST_DATABASE_INSTANCE displays information about the database environment.

  • DBA_HIST_DB_CACHE_ADVICE displays historical predictions of the number of physical reads for the cache size corresponding to each row.

  • DBA_HIST_DISPATCHER displays historical information for each dispatcher process at the time of the snapshot.

  • DBA_HIST_DYN_REMASTER_STATS displays statistical information about the dynamic remastering process.

  • DBA_HIST_IOSTAT_DETAIL displays historical I/O statistics aggregated by file type and function.

  • DBA_HIST_SHARED_SERVER_SUMMARY displays historical information for shared servers, such as shared server activity, common queues and dispatcher queues.

  • DBA_HIST_SNAPSHOT displays information on snapshots in the system.

  • DBA_HIST_SQL_PLAN displays the SQL execution plans.

  • DBA_HIST_WR_CONTROL displays the settings for controlling AWR.

See Also:

Oracle Database Reference for information about dynamic and static data dictionary views

6.3 Generating Automatic Workload Repository Reports

An AWR report shows data captured between two snapshots (or two points in time). AWR reports are divided into multiple sections. The content of the report contains the workload profile of the system for the selected range of snapshots. The HTML report includes links that can be used to navigate quickly between sections.

Note:

If you run a report on a database that does not have any workload activity during the specified range of snapshots, then calculated percentages for some report statistics can be less than 0 or greater than 100. This result means that there is no meaningful value for the statistic.

This section describes how to generate AWR reports and contains the following topics:

6.3.1 User Interface for Generating an AWR Report

The primary interface for generating AWR reports is Oracle Enterprise Manager. Whenever possible, generate AWR reports using Oracle Enterprise Manager.

If Oracle Enterprise Manager is unavailable, then generate AWR reports by running SQL scripts. The DBA role is required to run these scripts.

See Also:

Oracle Database 2 Day + Performance Tuning Guide for more information about generating AWR reports using Oracle Enterprise Manager

6.3.2 Generating an AWR Report Using the Command-Line Interface

This section describes how to generate AWR reports by running SQL scripts in the command-line interface. The DBA role is required to run these scripts.

This section contains the following topics:

6.3.2.1 Generating an AWR Report for the Local Database

The awrrpt.sql SQL script generates an HTML or text report that displays statistics from a range of snapshot IDs.

To generate an AWR report on the local database instance using the command-line interface: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrrpt.sql
    
  2. Specify whether you want an HTML or a text report:

    Enter value for report_type: text
    

    In this example, a text report is chosen.

  3. Specify the number of days for which you want to list snapshot IDs.

    Enter value for num_days: 2
    

    A list of existing snapshots for the specified time range is displayed. In this example, snapshots captured in the last 2 days are displayed.

  4. Specify a beginning and ending snapshot ID for the workload repository report:

    Enter value for begin_snap: 150
    Enter value for end_snap: 160
    

    In this example, the snapshot with a snapshot ID of 150 is selected as the beginning snapshot, and the snapshot with a snapshot ID of 160 is selected as the ending snapshot.

  5. Enter a report name, or accept the default report name:

    Enter value for report_name: 
    Using the report name awrrpt_1_150_160
    

    In this example, the default name is accepted and an AWR report named awrrpt_1_150_160 is generated.

6.3.2.2 Generating an AWR Report for a Specific Database

The awrrpti.sql SQL script generates an HTML or text report that displays statistics from a range of snapshot IDs using a specific database instance. This script enables you to specify a database identifier and instance for which the AWR report will be generated.

To generate an AWR report on a specific database instance using the command-line interface: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrrpti.sql
    
  2. Specify whether you want an HTML or a text report:

    Enter value for report_type: text
    

    In this example, a text report is chosen.

    A list of available database identifiers and instance numbers are displayed:

    Instances in this Workload Repository schema
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       DB Id    Inst Num DB Name      Instance     Host
    ----------- -------- ------------ ------------ ------------
     3309173529        1 MAIN         main         examp1690
     3309173529        1 TINT251      tint251      samp251
    
  3. Enter the values for the database identifier (dbid) and instance number (inst_num):

    Enter value for dbid: 3309173529
    Using 3309173529 for database Id
    Enter value for inst_num: 1
    
  4. Specify the number of days for which you want to list snapshot IDs.

    Enter value for num_days: 2
    

    A list of existing snapshots for the specified time range is displayed. In this example, snapshots captured in the last 2 days are displayed.

  5. Specify a beginning and ending snapshot ID for the workload repository report:

    Enter value for begin_snap: 150
    Enter value for end_snap: 160
    

    In this example, the snapshot with a snapshot ID of 150 is selected as the beginning snapshot, and the snapshot with a snapshot ID of 160 is selected as the ending snapshot.

  6. Enter a report name, or accept the default report name:

    Enter value for report_name: 
    Using the report name awrrpt_1_150_160
    

    In this example, the default name is accepted and an AWR report named awrrpt_1_150_160 is generated on the database instance with a database ID value of 3309173529.

6.3.2.3 Generating an Oracle RAC AWR Report for the Local Database

The awrgrpt.sql SQL script generates an HTML or text report that displays statistics from a range of snapshot IDs using the current database instance in an Oracle Real Application Clusters (Oracle RAC) environment.

Note:

In an Oracle RAC environment, Oracle recommends generating an HTML report (instead of a text report) because it is much easier to read.

To generate an AWR report for Oracle RAC on the local database instance using the command-line interface: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrgrpt.sql
    
  2. Specify whether you want an HTML or a text report:

    Enter value for report_type: html
    

    In this example, an HTML report is chosen.

  3. Specify the number of days for which you want to list snapshot IDs.

    Enter value for num_days: 2
    

    A list of existing snapshots for the specified time range is displayed. In this example, snapshots captured in the last day are displayed.

  4. Specify a beginning and ending snapshot ID for the workload repository report:

    Enter value for begin_snap: 150
    Enter value for end_snap: 160
    

    In this example, the snapshot with a snapshot ID of 150 is selected as the beginning snapshot, and the snapshot with a snapshot ID of 160 is selected as the ending snapshot.

  5. Enter a report name, or accept the default report name:

    Enter value for report_name: 
    Using the report name awrrpt_rac_150_160.html
    

    In this example, the default name is accepted and an AWR report named awrrpt_rac_150_160.html is generated.

6.3.2.4 Generating an Oracle RAC AWR Report for a Specific Database

The awrgrpti.sql SQL script generates an HTML or text report that displays statistics from a range of snapshot IDs using specific databases instances running in an Oracle RAC environment. This script enables you to specify database identifiers and a comma-delimited list of database instances for which the AWR report will be generated.

Note:

In an Oracle RAC environment, Oracle recommends generating an HTML report (instead of a text report) because it is much easier to read.

To generate an AWR report for Oracle RAC on a specific database instance using the command-line interface: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrgrpti.sql
    
  2. Specify whether you want an HTML or a text report:

    Enter value for report_type: html
    

    In this example, an HTML report is chosen.

    A list of available database identifiers and instance numbers are displayed:

    Instances in this Workload Repository schema
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       DB Id    Inst Num DB Name      Instance     Host
    ----------- -------- ------------ ------------ ------------
     3309173529        1 MAIN         main         examp1690
     3309173529        1 TINT251      tint251      samp251
     3309173529        2 TINT251      tint252      samp252
    
  3. Enter the value for the database identifier (dbid):

    Enter value for dbid: 3309173529
    Using 3309173529 for database Id
    
  4. Enter the value for the instance numbers (instance_numbers_or_all) of the Oracle RAC instances you want to include in the report:

    Enter value for instance_numbers_or_all: 1,2
    
  5. Specify the number of days for which you want to list snapshot IDs.

    Enter value for num_days: 2
    

    A list of existing snapshots for the specified time range is displayed. In this example, snapshots captured in the last 2 days are displayed.

  6. Specify a beginning and ending snapshot ID for the workload repository report:

    Enter value for begin_snap: 150
    Enter value for end_snap: 160
    

    In this example, the snapshot with a snapshot ID of 150 is selected as the beginning snapshot, and the snapshot with a snapshot ID of 160 is selected as the ending snapshot.

  7. Enter a report name, or accept the default report name:

    Enter value for report_name: 
    Using the report name awrrpt_rac_150_160.html
    

    In this example, the default name is accepted and an AWR report named awrrpt_rac_150_160.html is generated on the database instance with a database ID value of 3309173529.

6.3.2.5 Generating an AWR Report for a SQL Statement on the Local Database

The awrsqrpt.sql SQL script generates an HTML or text report that displays statistics of a particular SQL statement from a range of snapshot IDs. Run this report to inspect or debug the performance of a SQL statement.

To generate an AWR report for a SQL statement on the local database instance using the command-line interface: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrsqrpt.sql
    
  2. Specify whether you want an HTML or a text report:

    Enter value for report_type: html
    

    In this example, an HTML report is chosen.

  3. Specify the number of days for which you want to list snapshot IDs.

    Enter value for num_days: 1
    

    A list of existing snapshots for the specified time range is displayed. In this example, snapshots captured in the previous day are displayed.

  4. Specify a beginning and ending snapshot ID for the workload repository report:

    Enter value for begin_snap: 146
    Enter value for end_snap: 147
    

    In this example, the snapshot with a snapshot ID of 146 is selected as the beginning snapshot, and the snapshot with a snapshot ID of 147 is selected as the ending snapshot.

  5. Specify the SQL ID of a particular SQL statement to display statistics:

    Enter value for sql_id: 2b064ybzkwf1y
    

    In this example, the SQL statement with a SQL ID of 2b064ybzkwf1y is selected.

  6. Enter a report name, or accept the default report name:

    Enter value for report_name: 
    Using the report name awrrpt_1_146_147.html
    

    In this example, the default name is accepted and an AWR report named awrrpt_1_146_147 is generated.

6.3.2.6 Generating an AWR Report for a SQL Statement on a Specific Database

The awrsqrpi.sql SQL script generates an HTML or text report that displays statistics of a particular SQL statement from a range of snapshot IDs using a specific database instance.This script enables you to specify a database identifier and instance for which the AWR report will be generated. Run this report to inspect or debug the performance of a SQL statement on a specific database and instance.

To generate an AWR report for a SQL statement on a specific database instance using the command-line interface: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/awrsqrpi.sql
    
  2. Specify whether you want an HTML or a text report:

    Enter value for report_type: html
    

    In this example, an HTML report is chosen.

    A list of available database identifiers and instance numbers are displayed:

    Instances in this Workload Repository schema
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       DB Id    Inst Num DB Name      Instance     Host
    ----------- -------- ------------ ------------ ------------
     3309173529        1 MAIN         main         examp1690
     3309173529        1 TINT251      tint251      samp251
    
  3. Enter the values for the database identifier (dbid) and instance number (inst_num):

    Enter value for dbid: 3309173529
    Using 3309173529 for database Id
    Enter value for inst_num: 1
    Using 1 for instance number
    
  4. Specify the number of days for which you want to list snapshot IDs.

    Enter value for num_days: 1
    

    A list of existing snapshots for the specified time range is displayed. In this example, snapshots captured in the previous day are displayed.

  5. Specify a beginning and ending snapshot ID for the workload repository report:

    Enter value for begin_snap: 146
    Enter value for end_snap: 147
    

    In this example, the snapshot with a snapshot ID of 146 is selected as the beginning snapshot, and the snapshot with a snapshot ID of 147 is selected as the ending snapshot.

  6. Specify the SQL ID of a particular SQL statement to display statistics:

    Enter value for sql_id: 2b064ybzkwf1y
    

    In this example, the SQL statement with a SQL ID of 2b064ybzkwf1y is selected.

  7. Enter a report name, or accept the default report name:

    Enter value for report_name: 
    Using the report name awrrpt_1_146_147.html
    

    In this example, the default name is accepted and an AWR report named awrrpt_1_146_147 is generated on the database instance with a database ID value of 3309173529.

6.4 Generating Performance Hub Active Report

Performance Hub feature of EM Express provides an active report with a consolidated view of all performance data for a specified time period. The report is fully interactive; its contents are saved in a HTML file, which you can access offline using a web browser.

See Also:

Oracle Database 2 Day DBA for more information about Performance Hub feature of EM Express

This section describes how to generate Performance Hub active report and contains the following topics:

6.4.1 Overview of Performance Hub Active Report

Performance Hub active report enables you to view all performance data available for a time period that you specify. Different tabs are available in the Performance Hub, depending on whether real-time or historical data is selected for the time period. When real-time data is selected, more granular data is presented, because real-time data for the last hour is displayed. When historical data is selected, more detailed data is presented, but the data points are averaged out to the Automatic Workload Repository (AWR) interval for the selected time period.

This section describes Performance Hub active report and contains the following topics:

6.4.1.1 About Performance Hub Active Report Tabs

Performance Hub active report contains interactive tabs that enable you to view and navigate through performance data categorized into various performance areas.

The tabs contained in a Performance Hub active report include the following:

  • Summary

    The Summary tab provides an overview of system performance, including resource consumption, average active sessions, and load profile information. This tab is available for real-time data as well as historical data.

  • Activity

    The Activity tab displays ASH analytics. This tab is available for real-time data as well as historical data.

  • Workload

    The Workload tab displays metric information about the workload profile, such as call rates, logon rate, and top SQL. This tab is available for real-time data as well as historical data.

  • RAC

    The RAC tab displays metrics specific to Oracle RAC, such as the number of global cache blocks received and the average block latency. This tab is only available in Oracle RAC environments. This tab is available for real-time data as well as historical data.

  • Monitored SQL

    The Monitored SQL tab displays information about monitored SQL statements. This tab is available for real-time data as well as historical data.

  • ADDM

    The ADDM tab displays information for ADDM analysis tasks and Real-Time ADDM analysis reports. This tab is available for real-time data as well as historical data.

  • Current ADDM Findings

    The Current ADDM Findings tab displays a real-time analysis of system performance for the past 5 minutes. This tab is only available if the specified time period for the Performance Hub active report is within the past hour. This tab is available only for real-time data.

  • Database time

    The Database Time tab displays wait events by category for various metrics. This tab is available only for historical data.

  • Resources

    The Resources tab displays operating system and I/O usage statistics. This tab is available only for historical data.

  • System Statistics

    The System Statistics tab displays database and system statistics. This tab is available only for historical data.

6.4.1.2 About Performance Hub Active Report Types

You can choose the level of details displayed within each tab of the Performance Hub active report by selecting the report type.

The available report types for the Performance Hub active report include the following:

  • Basic

    Only the basic information for all the tabs is saved to the report.

  • Typical

    In addition to the information saved in the basic report type, the SQL Monitor information for the top SQL statements contained in the Monitored SQL tab and the ADDM reports are saved to the report.

  • All

    In addition to the information saved in the typical report type, the SQL Monitor information for all SQL statements contained in the Monitored SQL tab and all detailed reports for all tabs are saved to the report.

6.4.2 Command-Line User Interface for Generating a Performance Hub Active Report

You can generate a Performance Hub active report using the command-line interface in one of two ways:

6.4.3 Generating a Performance Hub Active Report Using a SQL Script

This section describes how to generate Performance Hub active report by running the perfhubrpt.sql SQL script in the command-line interface. The DBA role is required to run this script.

To generate a Performance Hub active report: 

  1. At the SQL prompt, enter:

    @$ORACLE_HOME/rdbms/admin/perfhubrpt.sql
    
  2. Specify the desired report type:

    Please enter report type: typical
    

    For information about the available report types, see "About Performance Hub Active Report Types".

  3. Enter the value for the database identifier of the database you want to use:

    Please enter database ID: 3309173529
    

    To use the local database, enter a null value (the default value). If you specify a database identifier for a database other than the local database, then the Performance Hub active report is generated from imported AWR data.

  4. Enter the value for the instance number of the database instance you want to use:

    Please enter instance number: all instances
    

    To specify all instances, enter all instances (the default value).

  5. Enter the desired time period by specifying an end time and a start time in the format of dd:mm:yyyy hh:mi:ss:

    Please enter end time in format of dd:mm:yyyy hh24:mi:ss: 03:04:2014 17:00:00
    Please enter start time in format of dd:mm:yyyy hh24:mi:ss: 03:04:2014 16:00:00
    
  6. Enter a report name, or accept the default report name:

    Enter value for report_name: my_perfhub_report.html
    

    In this example, a Performance Hub active report named my_perfhub_report is generated on all database instances with a database ID value of 3309173529 for the specified time period from 4:00 p.m. to 5:00 p.m on April 3, 2014.