Mastering Oracle Performance Diagnostics
Mastering Oracle Performance Diagnostics
Asfaw Gedamu
Introduction
In the world of modern data systems, database performance isn’t optional. It’s critical. Oracle
DBAs must quickly detect slowdowns, optimize workloads, and maintain stability under
pressure.
That’s where Oracle’s diagnostic arsenal, ASH, AWR, and ADDM, comes into play. These
tools deliver deep, actionable insights into performance, helping DBAs move from guesswork to
precision.
This hands-on guide shows you how to generate and automate ASH, AWR, and ADDM
reports using SQL and shell scripts. You’ll learn how to time snapshots smartly, stay compliant,
secure sensitive metrics, and build custom baselines that matter.
Here is your step-by-step playbook for keeping Oracle databases fast, stable, and future-
ready.
Prerequisites
1. Oracle Database Access : Ensure you have the necessary privileges (SYSDBA or DBA
role) to generate these reports.
2. Environment Setup :
o Oracle client installed on the machine running the script.
o $ORACLE_HOME and $PATH environment variables configured.
3. SQL*Plus : The Oracle command-line tool (sqlplus) must be available.
4. Database Credentials : Have the username, password, and database connection string
ready.
There is a practical script set for managing Oracle ASH, AWR, and ADDM reports efficiently
with SQL queries and shell scripting. It covers:
• ASH Report : Provides detailed information about active sessions over a specific time
period.
• AWR Report : Generates a comprehensive performance report for a specific time range.
• ADDM Report : Analyzes AWR data to provide diagnostic insights and
recommendations.
Oracle provides PL/SQL procedures to generate these reports. Below are the key procedures:
Purpose: Samples active session data every second and captures in-memory performance data,
such as blocking sessions, top waits, top SQLs, and sessions causing the most load.
Use it when: You need fine-grained, near real-time diagnostics or you want to investigate spikes
or performance anomalies within short time ranges
BEGIN
DBMS_WORKLOAD_REPOSITORY.ASH_REPORT_HTML(
l_dbid => <DBID>, -- Database ID
l_inst_num => <INSTANCE_NUMBER>, -- Instance Number
l_btime => TO_DATE('<BEGIN_TIME>', 'YYYY-MM-DD
HH24:MI:SS'),
l_etime => TO_DATE('<END_TIME>', 'YYYY-MM-DD
HH24:MI:SS'),
l_report => :report_clob -- Output variable for the
report
);
END;
/
Use it when: You want to analyze historical performance trends, find root causes of slowness, or
compare workloads over time.
BEGIN
DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(
l_dbid => <DBID>, -- Database ID
l_inst_num => <INSTANCE_NUMBER>, -- Instance Number
l_bid => <BEGIN_SNAP_ID>, -- Begin Snapshot ID
l_eid => <END_SNAP_ID>, -- End Snapshot ID
l_report => :report_clob -- Output variable for the
report
);
END;
/
Purpose: Uses AWR data to perform an automated analysis and provides actionable tuning
recommendations, e.g., reduce CPU load, fix high I/O SQLs, adjust memory settings.
Use it when: You want Oracle’s expert system to advise you, especially helpful for quick
diagnostics and performance improvement suggestions.
BEGIN
DBMS_ADDM.ANALYZE_DB(
task_name => 'ADDM_TASK',
begin_snap => <BEGIN_SNAP_ID>, -- Begin Snapshot ID
end_snap => <END_SNAP_ID>, -- End Snapshot ID
db_id => <DBID> -- Database ID
);
END;
/
#!/bin/bash
# Configuration
ORACLE_HOME=/path/to/oracle/home
export ORACLE_HOME
export PATH=$ORACLE_HOME/bin:$PATH
DB_USER="sys as sysdba"
DB_PASSWORD="your_password"
DB_CONNECTION="your_database_connection_string"
# Input Parameters
DBID=$1
INSTANCE_NUM=$2
BEGIN_TIME=$3
END_TIME=$4
BEGIN_SNAP_ID=$5
END_SNAP_ID=$6
2. Make it executable:
chmod +x generate_oracle_reports.sh
Bonus Tips
Example:
crontab -e
0 8 * * * /home/oracle/scripts/generate_and_email_awr.sh >>
/home/oracle/logs/awr_cron.log 2>&1
Notes
The provided Shell script and SQL queries allow you to generate ASH , AWR , and ADDM
reports programmatically. These tools are essential for diagnosing and optimizing Oracle
database performance.
1. Snapshot Timing:
Choose meaningful intervals — not just arbitrary hours. Use workload events (peak
traffic, backup windows) to time snapshots.
2. Licensing Compliance:
AWR/ASH/ADDM are part of the Diagnostic Pack — ensure your environment is
licensed for it.
3. Custom Baselines:
Establish performance baselines for comparison, especially before/after
migrations, patching, or architectural changes.
1. Snapshot Timing
Snapshots should be timed based on workload events (e.g., peak traffic or backup
windows). Use Oracle's DBMS_WORKLOAD_REPOSITORY package to manage snapshots.
This script schedules snapshots during peak traffic hours (e.g., 9 AM–5 PM) and backup
windows (e.g., midnight).
#!/bin/bash
This script checks if the required features are licensed and sends an alert if they are not.
#!/bin/bash
3. Custom Baselines
BEGIN
DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(
start_snap_id => 100, -- Start snapshot ID
end_snap_id => 200, -- End snapshot ID
baseline_name => 'Pre_Migration_Baseline'
);
END;
/
#!/bin/bash
# Input parameters
START_SNAP_ID=$1
END_SNAP_ID=$2
BASELINE_NAME=$3
# Create baseline
sqlplus -s / as sysdba <<EOF
BEGIN
DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(
start_snap_id => $START_SNAP_ID,
end_snap_id => $END_SNAP_ID,
baseline_name => '$BASELINE_NAME'
);
END;
/
EXIT;
EOF
Manage AWR snapshot retention policies to balance history depth with storage usage.
# Display results
echo "Access Permissions for AWR/ASH/ADDM:"
echo "$ACCESS_PERMISSIONS"
Connect insights from AWR/ASH/ADDM with tools like Oracle Enterprise Manager, Grafana,
or Prometheus.
This script exports AWR data to a CSV file for ingestion into monitoring tools.
#!/bin/bash
Conclusion
The above SQL queries and shell scripts provide a comprehensive solution for managing
AWR/ASH/ADDM snapshots, ensuring licensing compliance, creating custom baselines,
managing retention policies, securing access, and integrating with monitoring tools. These scripts
can be customized further based on specific requirements.