The responsibility of a database administrator lies not only in creating a database and
ensuring that it is available at all times to its users, but also making sure it is operating in
top condition. A well tuned and optimized database can draw parallels with a well oiled
machine. However achieving a well tuned and optimized database can be quite a task.
Anyone setting out to tune it should have a thorough understanding of the architecture of
the database, the applications being run on the database and the goals that you are trying
to achieve in the form of concrete values.
Performance tuning has always been an important responsibility for a database
administrator. With earlier releases of the Oracle database, a good part of the database
administrator's time was spent on monitoring database health, identifying bottlenecks and
improving system performance. It was not only tedious and complicated, but also prone
to errors if you are not using proper guidelines.
Very often the most important question is where and with what do we start? The
administrator may also determine if a pattern exists. In earlier versions of administrators
performed tuning by gathering and analyzing statistics in the database. The information
mostly in the form of raw data that the DBA had to deal with could be plenty and quite
difficult to compile. Some administrators would probably invest in a third-party tool or a
homegrown tool to collect elaborate statistics during database operation and derive
performance metrics from them. Hence gathering relevant statistics is a crucial part of
performance tuning.
One of the major enhancements made by the Oracle 10g database over its earlier versions
is a complete overhaul to the way performance tuning is done. The task of the
administrator has been simplified considerably with the introduction of automated tools,
new features and advisors. The Oracle database can provide real information about the
database's health.
In Oracle 10g, a new component known as the Automatic Workload Repository offers a
significant boost to statistics gathering and performance tuning related tasks.
Raw data that is collected is known as base statistics. The number of physical reads in the
system since startup is a base statistic. Base statistics are collected automatically by
Oracle.
Metrics are derived from base statistics. The MMON background process periodically
updates metric data from the corresponding base statistics. Metrics track the rates of
change in the Oracle database. Each metric is associated with a metric name, and a
unique identifier known as the metric number. The average physical reads per second in
the database is an example of a metric. Metrics are used for self-tuning purposes. Metric
data can be accessed using views such as V$SYSMETRIC, V$SESSMETRIC and so on.
Since metrics are always created, determining the changed rate for a particular statistic
becomes very easy and is always readily available.
Statistics Levels
The amount of statistics captured can be controlled using the initialization parameter
STATISTICS_LEVEL. The three values that can be taken by the parameter are:
BASIC The computation of AWR statistics and metrics is turned off. All self-tuning
capabilities are turned off. You can manually capture AWR statistics using procedures in
the DBMS_WORKLOAD_REPOSITORY package.
TYPICAL This is the default and recommended value. A part of the statistics is
collected.
ALL All possible statistics are captured.
Creating Baselines
A baseline is a mechanism by which you can tag set of snapshot data pertaining to
important periods. Baselines are defined on pairs of snapshots. A baseline may be
provided with a user generated name or a system generated identifier. A baseline can be
created by executing the DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE
procedure.
Once a baseline is created it remains in the database until you drop them. Baselines are
usually created to set up baselines from some representative periods in the past.
The Structure of the Workload Repository Schema
The WR schema is made up of two types of tables, namely Metadata tables and Historical
statistical tables. Metadata tables are used to control, process and describe the WR tables.
These tables are used to determine when to perform snapshots and what to capture to
disk. The metadata tables are prefixed with WRM$.
Historical statistical tables store statistical data generated by the Oracle database based on
the current workload. The historical statistical tables are prefixed with WRH$.
Data dictionary views can be used to query the workload repository. Any view related to
the historical information in the Workload repository has the DBA_HIST_ prefix.
Workload Repository Capture and Purging Policy
The MMON background process is responsible for capturing in-memory statistics and
creating the snapshots every 60 minutes. However you can control the interval within
which the snapshots will be captured (INTERVAL) as well the duration of time that the
AWR information is retained in the workload repository (RETENTION). This is done by
using DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS
packaged procedure.
The RETENTION parameter of the procedure indicates how long (in terms of days), the
AWR information must be retained. By default this is 7 days. Automatic purging of data
can be turned off by setting RETENTION to zero. However a minimum of one day of
history must be maintained.
The INTERVAL parameter of the procedure indicates how often the system will
automatically generate snapshots. The value of this parameter cannot be set to less than
10 minutes. The default is 60 minutes. If you set he INTERVAL to 0, automatic
capturing of snapshots is turned off.
Command Syntax:
DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS (
RETENTION NUMBER, INTERVAL NUMBER);
In this example displayed below, the retention period is specified as 43200 minutes (30
days) and the interval between each snapshot is specified as 30 minutes. If NULL is
specified, the existing value is preserved..
BEGIN
DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS (
retention => 43200,
interval => 30);
END;
/
You can configure RETENTION and INTERVAL parameters from the Enterprise
Manager (EM) console. Select Database -> Administration -> Workload Repository.
The DBMS_WORKLOAD_REPOSITORY Package
This PL/SQL package is used to manage the Workload Repository. It contains various
procedures that can be used to create, drop, and modify snapshots and baselines.
Procedure Name
CREATE_SNAPSHOT
DROP_SNAPSHOT_RANGE
CREATE_BASELINE
DROP_BASELINE
MODIFY_SNAPSHOT_SETTINGS
Description of Procedure
To manually create a snapshot
immediately
To drop a range of snapshots
To create a single baseline
To drop a single baseline
To modify a snapshot settings
For example
SQL> EXECUTE
DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(start_snap_id
NUMBER, end_snap_id NUMBER, baseline_name VARCHAR2)
Snapshots that belong to baselines are retained until the baseline is dropped.
Database Usage Metrics
Using you the workload repository you can keep track of the Database Usage
Metrics. The MMON process tracks and records this information once a week.
The metrics are divided into the two categories.
The database feature usage statistics - you get information about Advanced
Replication, Oracle Streams, advanced queuing, Virtual Private database etc.
To retrieve this information you can query
DBA_FEATURE_USAGE_STATISTICS view or use the EM console. You
can access the Database Features Usage Statistics page by clicking the
Administration Tab on the Database Home page.
[SCREENSHOT ]
The High Water Mark value for certain database attributes such as the size of
the largest segment, maximum number of sessions, maximum number of tables
etc. To retrieve information you can query the
DBA_HIGH_WATER_MARK_STATISTICS view or use the EM console.
[SCREENSHOT]
AWR Reports
Summary reports on statistics stored in the workload repository can be generated by
using the SQL*Plus script awrrpt.sql. The report provides information about the
overall behavior of the system over a period of time. The reports an either in a text file or
HTML format.
The script should be run as a SYSDBA user. You will be prompted for the format (either
text or HTML), the number of days of snapshots to choose from, the begin snap_id and
end snap_id, and the name of the report file.
First, you need to specify whether you want an HTML or a text report.
Enter value for report_type: text
Specify the number days for which you want to list snapshot Ids.
Enter value for num_days: 2
After the list displays, you are prompted for the beginning and ending snapshot Id for the
workload repository report.
Enter value for begin_snap: 150
Enter value for end_snap: 160
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_150_160
Description
Displays active database session activity. The data
in this view is sampled every second.
Provide metric data to track the performance of the
system.
$METRICNAME displays the mapping of the name of
metrics to their metric ID.
V$SERVICEMETRIC displays values of metrics for
the most recent 60-second interval. A history of
the last one hour will be kept in the system.
Server Generated Alerts Using this feature the Oracle Server can
automatically detect certain undesirable alarming situations. The Oracle server
can be configured to respond to such situations and alert the DBA if the situation
does arise.
Reactive Monitoring
When using reactive monitoring the DBA can make use of the powerful new data sources
as well as performance-reporting capabilities of the Oracle 10g database to detect and
resolve bottlenecks. These new data sources are meant to capture important and relevant
information about the database's health. Bottlenecks in the database can be detected
manually using a drill-down method with a few mouse clicks.
THE AUTOMATIC DATABASE DIAGNOSTIC MONITOR
This new feature of Oracle 10g is used to proactively monitor the database. It is a serverbased performance expert. It ties up all sorts of relevant information in the database to
perform a detailed analysis and generate a list of recommendations. The types of
problems that ADDM considers include:
CPU bottlenecks - Is the system CPU bound by Oracle or some other application?
Undersized Memory Structures - Are the Oracle memory structures, such as the
SGA, PGA, and buffer cache, adequately sized?
I/O capacity issues - Is the I/O subsystem performing as expected?
High load SQL statements - Are there any SQL statements which are consuming
excessive system resources?
High load PL/SQL execution and compilation, as well as high load Java usage
RAC specific issues - What are the global cache hot blocks and objects; are there
any interconnect latency issues?
Sub-optimal use of Oracle by the application - Are there problems with poor
connection management, excessive parsing, or application level lock contention?
Database configuration issues - Is there evidence of incorrect sizing of log files,
archiving issues, excessive checkpoints, or sub-optimal parameter settings?
Concurrency issues - Are there buffer busy problems?
Hot objects and top SQL for various problem areas
Within the database statistics are gathered automatically every 60 minutes and stored in
the automatic workload repository (AWR), in the form of snapshots. The information
gathered is very precise. The ADDM is scheduled to run automatically by the MMON
background process. Every time a snapshot is taken, the ADDM is triggered to do an
analysis of the period corresponding to the last two snapshots.
The results generated by the analysis are stored in the AWR and is accessible through the
Enterprise Manager Console.
It is possible to invoke the ADDM from the EM console or manually. This option gives
you the ability to run an analysis across any two snapshots. By doing this, ADDM
provides tuning recommendations on the user-defined time period.
In earlier versions of Oracle, statistics gathering could be done using Statspack. However
this method lacks granularity of statistics. Another important feature is that ADDM
concentrates its analysis on issues that impact the system the most. Using ADDM, you
can easily identify top performance issues, such as Top SQL, I/O issues or Configuration
issues to name a few. This is primarily because a new methodology implemented in
ADDM.
The methodology used by ADDM is based on a wait and time statistic model. The model
is helpful in determining where time is spent within the database. The ADDM analysis
uses a top-down approach that focuses mainly on determining resource bottlenecks.
It uses a tree structure to represent all possible tuning issues. The root of the tree
represents the symptoms and going down to the leaves helps identify the root causes. The
ADDM walks down a tree using the time-based thresholds for each node. If the timebased threshold is not exceeded for a specific node, the ADDM prunes the corresponding
subtree. This way the ADDM concentrates only on problem areas. In the diagram below
the waits due to concurrency are an issue and non-issue subtrees such as the one
associated with RAC and IO Waits are pruned by the ADDM.
CONCURRENCY
BUFFER BUSY
PARSE LATCHES
SYSTEM WAIT
RAC WAITS
IO WAITS
Some of the performance issues that were not detected by Statspack are:
Excessive login and logoff
Memory under-sizing
Hot blocks and objects with SQL
RAC service issues
Locks and ITL contention
Checkpointing causes
PL/SQL; Java time
ADDM Output
The output generated by ADDM is best viewed using the Enterprise Manager Console.
After an analysis, the ADDM reports its findings along with the impact on the database.
The impact is measured in terms of time spent. The ADDM findings include symptoms
and root causes. A number or recommendations are also generated. Recommendations
generated by ADDM include:
Details of the latest ADDM run can be obtained from the EM console. First select the
Database Home page -> Diagnostic Summary region -> Performance Findings Link
-> ADDM Findings Page. Specific areas of interest on this page are the View Report
Button. This gives you details of the performance analysis in the form of a text report. By
clicking on a specific issue, you are directed to a Performance Finding Details page.
This page also gives you recommendations to solve the corresponding issue. The Benefit
column gives you the maximum reduction in database elapse time if a recommendation is
implemented. ADDM may also suggest that you invoke a specific advisor for future
analysis of certain problem areas. For e.g., a faulty SQL statement can be fixed by
running the SQL Tuning Advisor.
Description
This view provides basic information
about existing tasks, such as the task Id,
task name, and when created.
DBA_ADVISOR_LOG
This view contains the current task
information, such as status, progress, error
messages, and execution times.
DBA_ADVISOR_RECOMMENDATIONS This view displays the results of completed
diagnostic tasks with recommendations for
the problems identified in each run.
DBA_ADVISOR_FINDINGS
This view displays all the findings and
symptoms that the diagnostic monitor
encountered along with the specific
recommendation.
Server-Generated Alerts
This feature is one of the principal components of the common manageability
infrastructure. Server-generated alerts are the capability of the Oracle database to
automatically detect alarming situations that may arise in the database. If an
alarming situation occurs, the DBA can be alerted with suggestions for remedial
actions.
An alert may be configured to identify some internally determined or user-defined
problem situation. An alert can be contain information about the object such as a
tablespace, a description of the problem, a brief advice on remedial action, the
name of an advisor that can provide more detailed recommendations and the status
or level of severity.
An alert may be queued in a predefined queue called ALERT_QUE that is owned
by the SYS user. The Enterprise Manager may be used to notify the DBA about
outstanding alerts. This may be done by means of email or pager. Server-generated
alerts are always displayed on the EM console.
There are two kinds of server-generated alerts:
Threshold
Non-threshold alerts.
Most of the alerts in the Oracle database are configured by setting two threshold
values, namely Warning threshold and Critical threshold. In the Oracle database
there are about 161 metrics for which you can define thresholds. Some of them
being User Commits Per Sec, CPU Time Per call, SQL service Response Time,
Physical Reads Per Second. A threshold alert is automatically cleared when the
DBA has responded to the alert.
A threshold alert is displayed in the DBA_OUTSTANDING_ALERTS view and
when cleared is sent to the DBA_ALERT_HISTORY view.
Server generated errors may also correspond to database events and are known as
non-threshold errors. These errors go directly to the history table. Examples of
some situations that result in alerts are:
Snapshot too old errors
Resumable session suspended
Recovery Area Low on Free space errors
Certain alerts are always enabled in the database and may be called out-of-the-box
alerts. To mention a few:
Tablespace usage
Snapshot too old
Resumable session suspended
Recovery Area Low on Free space errors
The SERVER-ALERT Usage
As a DBA if you want the Oracle database to notify you of alert situations, you
can use the model given below:
Using the EM console or PL/SQL procedure set the threshold limits for the
server alert metrics.
Identify a means to be notified, either by Email address, blackout period or
pager).
When the alert is generated, the alert displays in the EM console. EM sends
out a notification to the administrators.
You may use the suggestions provided to correct the alert.
The STATISTIC_LEVEL initialization parameter should be set to TYPICAL or
ALL for this functionality.
Setting Threshold Values Using Pl/Sql
The new DBMS_SERVER_ALERT package is used to set up thresholds on
metrics.
PROCEDURE NAME
SET_THRESHOLD
GET_THRESHOLD
Description
Used to define threshold settings for a
given metric
Used to read settings for a given metric
The parameters are explained in the order they appear in the example:
Advisors are server components that provide relevant feedback about resource
utilization and performance with respect to specific database components.
The advisors use a common data source known as the Automatic workload
repository (AWR). There is a uniform interface and a seamless integration
between the different advisors available in Oracle 10g.
A list of available advisors is given below:
1. Automatic Database Diagnostic Monitor (ADDM)
This advisor monitors the overall health of the database. Uses a top-down
approach starting with symptoms and coming down to the root causes. It
also comes up with recommendations for fixing the problems. This advisor
is a central component to the advisory framework and can call upon other
advisors.
2. SQL Tuning Advisor
Provides SQL statement tuning advice.
3. SQL Access Advisor
Deals with schema issues and determines optimal ways to access data.
4. Memory Advisor
An advisor for system memory and optimizes the memory for an instance.
Used when automatic memory tuning is not enabled.
a. PGA Advisor Gives detailed advice and recommendations on work
areas along with optimal usage of PGA memory based on workload
characteristics.
b. SGA Advisor tunes and provides recommendations for the SGA,
depending on the access to various components in the SGA.
c. Buffer Cache Advisor Predicts cache hit rates for buffer access for
different sizes of the buffer cache.
d. Library Cache Advisor Predicts the cursor cache hit rate for he
library cache for different sizes.
5. Segment Advisor
Responsible for space issues regarding a database object. It can analyze
growth trends.
6. Undo Advisor Advices and recommends values for undo retention and
size of the undo tablespace based on current workload and workload
history.
An advisor may be invoked during the MMON performing its monitoring
actions or in a wizard in some of the DBA tools. Certain server alerts may also
recommend the DBA to view a certain Advisor for additional information.
Attributes of Advisors
Can operate in LIMITED and COMPREHENSIVE Modes: Limited
displays a relatively shallow analysis whereas a comprehensive mode
displays a more in-depth analysis.
Time limit: Specifies a maximum amount of time that the advisor can
run.
Interruptible: Specifies if an advisor provides partial results upon being
interrupted.
User Directive: Specifies whether the advisor can take user directives.
These could influence the recommendations provided.
Invoking the Advisors from EM Console
Select the Database Control Home Page -> Related Links -> Advisor Central
Link -> Advisor Central Page.
From the advisor central page you can list all the advisor tasks that were registered
in the workload repository.
The DBMS_ADVISOR Package
This is a package that is new to Oracle 10g. It consists of various procedures and
constants that are used by advisor modules. To execute any of the procedures you
must be granted the ADVISOR privilege.
PROCEDURE
CREATE_TASK
DELETE_TASK
EXECUTE_TASK
INTERRUPT_TASK
GET_TASK_REPORT
RESUME_TASK
UPDATE_TASK_ATTRIBUTES
SET_TASK_PARAMETER
MARK_RECOMMENDATION
GET_TASK_SCRIPT
DESCRIPTION
Creates a new task in the repository
Deletes a task from the repository
Initiates execution of the task
Suspends a task that is currently
executing
Text report about recommendations
Resumes a suspended task
Updates task attributes
Modifies a task parameter
Marks one or more recommendations as
accepted, rejected or ignored
Creates a script of all the
recommendations that are accepted.
VIEW NAME
DBMS_ADVISOR_DEFINITIONS
DBMS_ADVISOR_TASKS
DBA_ADVISOR_USAGE
In Oracle 10g, there may be certain tables or schemas that you don't want to
subject to the automatic statistics gathering feature. In this case you can lock them
using a LOCK_TABLE_STATS or LOCK_SCHEMA_STATS procedure of the
DBMS_STATS package. Once you have locked the statistics on a table, all the
dependent statistics such as tables statistics, column statistics, histograms and
dependent index statistics are also locked.
SQL> EXECUTE
DBMS_STATS.LOCK_TABLE_STATS('schema','tablename');
SQL> EXECUTE DBMS_STATS.LOCK_SCHEMA_STATS('schema');
To unlock the statistics on a specified table or schema you can use the
UNLOCK_TABLE_STATS or UNLOCK_SCHEMA_STATS procedure of the
DBMS_STATS package.
You can however keep in mind that it is possible to overwrite statistics even if
they are locked by setting the value of the FORCE argument to TRUE when using
the DELETE_*_STATS, IMPORT_*_STATS, SET_*_STATS procedures of the
DBMS_STATS package.
To display the start and end times of all DBMS_STATS operations you can query
the DBA_OPTSTAT_OPERATIONS data dictionary view. The information in
this view is purged by default after 31 days. You can modify this retention period
value if desired.
In Oracle 10g, index statistics collection occurs by default during Index creation
and rebuilding unless the statistics are locked. The COMPUTE STATISTICS
clause of the CREATE INDEX and ALTER INDEX commands are now obsolete.
GATHER_STATS_JOB
Optimizer statistics are automatically gathered using the job GATHER_STATS_JOB.
This job gathers statistics on all objects in the database which have missing or stale
statistics.
The job is created automatically at database creation time and is managed by the
Scheduler. The Scheduler runs this job when the maintenance window is opened. By
default, the maintenance window opens every night from 10P.M to 6 A.M and all day
on weekends. The GATHER_STATS_JOB continues until it finishes, even if it
exceeds the allocated time for the maintenance window. This behavior can be
changed.
The GATHER_STATS_JOB job gathers optimizer statistics by invoking the
DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC procedure.
You can verify that the job exists by querying DBA_SCHEDULER_JOBS view.