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:
-
Data visibility and privilege requirements may differ when using AWR features with pluggable databases (PDBs). For information about how manageability features, including the AWR features, work in a multitenant container database (CDB), see Oracle Multitenant Administrator’s Guide.
-
License for Oracle Diagnostic Pack is required to use the AWR features described in this chapter.
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
andV$SESS_TIME_MODEL
views -
Some of the system and session statistics collected in the
V$SYSSTAT
andV$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:
-
"About Database Statistics" for information about the various types of database statistics
-
Oracle Database Reference for more information about the views
V$SYS_TIME_MODEL
,V$SESS_TIME_MODEL
,V$SYSSTAT
, andV$SESSTAT
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
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:
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
Moving Window Baselines
A moving window baseline corresponds to all AWR data that exists within the AWR retention period. 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. 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
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
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.
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.
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.
Oracle Database uses the SYSAUX
as the default tablespace, therefore AWR data is typically stored there. You can specify a different tablespace where AWR data is to be stored. When AWR is storing information from multple DBIDs, such as imported snapshots, AWRHub, etc., the tablespace can be specified for each DBID. To check the current tablespace, refer to DBA_HIST_WR_CONTROL.TABLESPACE_NAME
.
See Also:
"Modifying Snapshot Settings" for information about changing the default values for the snapshot interval and retention period