8 Monitoring Tuning And Performance

Database Administration · Unit 8

Monitoring, Tuning and Performance

Exam-focused notes for Monitoring, Tuning and Performance (Database Administration, BIT352): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.

Monitoring, Tuning and Performance in short

This chapter covers how a DBA finds slow areas, tunes SQL, controls locks and records user actions. These tools keep a busy database fast and safe.

Monitoring, Tuning and Performance: notes

Oracle AWR overview

The Automatic Workload Repository (AWR) collects and stores performance statistics of the database. The data is kept in the SYSAUX tablespace.

  • A snapshot is a copy of the statistics at one moment.
  • By default a snapshot is taken every 60 minutes.
  • Snapshots are kept for a fixed time, 8 days by default in recent versions (check DBA_HIST_WR_CONTROL on your system).
  • The background process MMON takes the snapshots.

An AWR report compares two snapshots. It shows load, wait events, top SQL, memory use and I/O. AWR is part of the Diagnostics Pack, which needs a licence.

Manage snapshots with the package DBMS_WORKLOAD_REPOSITORY. Times are in minutes.

EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;

EXEC DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(
       retention => 11520, interval => 30);

EXEC DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(
       low_snap_id => 100, high_snap_id => 110);

AWR report viewing procedures

The report is made by the script awrrpt.sql in $ORACLE_HOME/rdbms/admin. Run it as a privileged user in SQL*Plus.

CONNECT / AS SYSDBA
@?/rdbms/admin/awrrpt.sql

The script asks for:

  • The report type: html or text.
  • The number of days of snapshots to list.
  • The begin snapshot ID and the end snapshot ID.
  • The report file name.

Then open the file. Important sections are Load Profile, Top 5 Timed Foreground Events, SQL ordered by Elapsed Time, and Instance Efficiency percentages. Use two snapshots from a busy period, not from a quiet one. awrrpti.sql makes a report for a chosen instance.

SQL tuning definition and process

SQL tuning means making a SQL statement use fewer resources and run faster. The goal is to reduce time, CPU and disk reads.

The tuning process:

  • Find the problem SQL using AWR, V$SQL or user complaints.
  • Look at the execution plan, which is the path Oracle uses to run the statement.
  • Check that table and index statistics are current.
  • Find causes such as full table scans, missing indexes and poor joins.
  • Change the SQL, add an index or give hints, and measure again.
  • Repeat until the time is good.
EXPLAIN PLAN FOR
  SELECT * FROM emp WHERE deptno = 10;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

EXEC DBMS_STATS.GATHER_TABLE_STATS('SCOTT','EMP');
CREATE INDEX emp_dept_ix ON emp(deptno);

Common fixes: avoid SELECT *, use bind variables, do not wrap indexed columns in functions, and join on indexed columns.

What this unit covers

  • Oracle AWR overview
  • AWR report viewing procedures
  • SQL tuning definition and process
  • SQL Tuning Advisor usage
  • Database performance tuning
  • Locking levels in oracle
  • Lock acquisition methods
  • Database auditing concepts
  • Standard auditing in oracle
  • Audit trail definition

Locking levels in oracle

2081 · 10 marks

Describe levels of locking in oracle. Discuss the methods used to acquire locks in oracle.[10]

Show solved answer

Levels of Locking in Oracle and Methods to Acquire Locks

Note: The reference notes did not contain specific content on this topic. The following answer is based on standard Oracle database concepts as taught in database management system courses at the BSc CSIT level.


Introduction to Locking in Oracle

A lock is a mechanism that prevents destructive interaction between transactions accessing a shared resource. Oracle Database uses a multi-level locking strategy to provide maximum concurrency while maintaining data integrity and consistency.

Oracle's locking philosophy is:

  • Locks are acquired automatically (implicitly) by DML statements.
  • Oracle never escalates locks (a key difference from many other RDBMS).
  • Readers do not block writers, and writers do not block readers.

Levels of Locking in Oracle

Oracle implements locking at multiple granularity levels:


1. Row-Level Locks (TX Locks - Transaction Locks)

  • The finest granularity of locking in Oracle.
  • When a transaction modifies a row (INSERT, UPDATE, DELETE, SELECT FOR UPDATE), Oracle places an exclusive lock on that specific row.
  • Other transactions can read the row (using MVCC - Multi-Version Concurrency Control) but cannot modify it until the lock is released.
  • Row-level locks are stored within the data block itself (in the row header), not in a separate lock table.
  • This allows Oracle to lock millions of rows without lock escalation.

Example:

UPDATE employees SET salary = 5000 WHERE emp_id = 101;
-- Only row with emp_id = 101 is locked

2. Table-Level Locks (TM Locks - DML Locks)

  • Placed on the entire table to protect the table structure while row-level locks are held.
  • Table locks do not prevent other transactions from accessing rows; they prevent DDL operations (like DROP TABLE or ALTER TABLE) from conflicting with ongoing DML.
  • Oracle supports five modes of table-level locks:
ModeAbbreviationDescription
Row ShareRS (SS)Allows concurrent access; prevents exclusive table lock
Row ExclusiveRX (SX)Used during DML; prevents share and exclusive locks
ShareSAllows only reads; prevents DML by others
Share Row ExclusiveSRX (SSX)More restrictive than Share; only one transaction can hold it
ExclusiveXFull exclusive access; no other DML or DDL allowed

Lock Compatibility Matrix:

RSRXSSRXX
RSYYYYN
RXYYNNN
SYNYNN
SRXYNNNN
XNNNNN

(Y = Compatible, N = Incompatible)


3. Page/Block-Level Locks

  • Oracle does not use page-level or block-level locking as a standard locking granularity.
  • This is a deliberate design choice to avoid unnecessary contention.
  • Lock information is embedded in the block header (Interested Transaction List - ITL), but this is not a separate locking level.

4. Database-Level Locks (DDL Locks)

  • Protect the definition (schema) of database objects during DDL operations.
  • Three types:
    • Exclusive DDL Lock: Acquired during DROP, ALTER, CREATE operations. No other DDL or DML allowed on the object.
    • Share DDL Lock: Acquired during CREATE PROCEDURE, CREATE VIEW. Allows other share DDL locks but not exclusive.
    • Breakable Parse Lock: Held by SQL statements in the shared pool. Can be broken if a DDL operation requires it.

5. System/Dictionary Locks (Internal Locks and Latches)

  • Latches: Low-level serialization mechanisms protecting internal Oracle memory structures (e.g., SGA, buffer cache). They are not user-visible.
  • Internal Locks: Protect internal database structures like data file headers and control files.
  • These are managed entirely by Oracle and are not accessible to users.

Methods Used to Acquire Locks in Oracle

Oracle provides both implicit (automatic) and explicit (manual) methods to acquire locks.


Method 1: Implicit (Automatic) Locking

Oracle automatically acquires locks when DML statements are executed. The user does not need to request them.

SQL StatementRow LockTable Lock Mode
INSERTExclusive (X) on new rowRX
UPDATEExclusive (X) on modified rowsRX
DELETEExclusive (X) on deleted rowsRX
SELECTNo lockNo lock (MVCC used)

Example:

UPDATE departments SET dept_name = 'HR' WHERE dept_id = 10;
-- Oracle automatically acquires: Row X lock + Table RX lock

Locks are automatically released when the transaction ends (COMMIT or ROLLBACK).


Method 2: SELECT ... FOR UPDATE (Explicit Row Lock)

  • Used to explicitly lock rows that a transaction intends to modify later.
  • Prevents other transactions from modifying or locking the same rows.
  • Useful when a transaction reads data and then updates it later in the same transaction.

Syntax:

SELECT column_list
FROM table_name
WHERE condition
FOR UPDATE [OF column] [NOWAIT | WAIT n | SKIP LOCKED];

Options:

  • NOWAIT: Returns an error immediately if the lock cannot be acquired.
  • WAIT n: Waits for n seconds before returning an error.
  • SKIP LOCKED: Skips rows that are already locked.

Example:

SELECT emp_id, salary
FROM employees
WHERE dept_id = 10
FOR UPDATE NOWAIT;
-- The selected rows are locked in exclusive mode until COMMIT or ROLLBACK

Method 3: LOCK TABLE (Explicit Table Lock)

  • Used when a transaction wants to lock an entire table rather than individual rows.
  • The lock mode is stated explicitly, which lets the developer decide how much concurrency to give up.

Syntax:

LOCK TABLE table_name IN lock_mode MODE [NOWAIT];

Common lock modes:

ModeMeaning
ROW SHARE (RS)Allows concurrent access, only prevents exclusive table locks
ROW EXCLUSIVE (RX)Acquired automatically by INSERT, UPDATE and DELETE
SHARE (S)Allows other readers, blocks all writers
SHARE ROW EXCLUSIVE (SRX)Allows readers only, one transaction at a time
EXCLUSIVE (X)Strictest, only queries are allowed on the table

Example:

LOCK TABLE employees IN EXCLUSIVE MODE NOWAIT;

Method 4: DDL Locks (Acquired Automatically)

  • Oracle takes a DDL lock on an object whenever a DDL statement such as ALTER TABLE or DROP TABLE refers to it, so the definition cannot change under a statement that is still compiling or executing.
  • These locks are never requested by the user; they are held only for the duration of the DDL statement.

Conclusion

Oracle locks at several granularities, from the row level (TX locks, the normal case) up through table level (TM locks), block level, and the DDL and internal locks that protect the data dictionary. Locks are acquired in two ways: implicitly, when a DML statement runs and Oracle takes the row and table locks it needs, and explicitly, through SELECT ... FOR UPDATE for rows or LOCK TABLE for whole tables. Oracle's default is deliberately conservative in favour of concurrency, since readers never block writers and writers never block readers thanks to multiversion read consistency, and every lock is released automatically at COMMIT or ROLLBACK.

Open this answer on its own page →

Oracle AWR overview

2081 · 5 marks

What is Oracle AWR? How AWR report is viewed in oracle? [5]

Show solved answer

Oracle AWR (Automatic Workload Repository)

What is Oracle AWR?

AWR (Automatic Workload Repository) is a built-in Oracle Database feature that automatically collects, processes, and maintains performance statistics for problem detection and self-tuning purposes.

Note: The following answer is based on standard Oracle Database documentation, as no specific curriculum notes were provided.

Key Characteristics of AWR:

  • AWR is a repository of historical performance data stored in the SYSAUX tablespace of the Oracle database.
  • It collects snapshots of database performance statistics at regular intervals (default: every 60 minutes).
  • Snapshots are retained for a default period of 8 days, after which they are automatically purged.
  • It is managed by the MMON (Manageability Monitor) background process.

Data Collected by AWR:

CategoryExamples
Wait statisticsTop wait events, wait times
SQL statisticsHigh-load SQL statements
System statisticsCPU usage, I/O, memory
Object statisticsSegment-level access info
Time model statisticsDB time, parse time

Purpose of AWR:

  • Identify performance bottlenecks
  • Compare database performance between two time periods
  • Support the Automatic Database Diagnostic Monitor (ADDM)
  • Assist DBAs in capacity planning and tuning

How AWR Report is Viewed in Oracle

AWR reports can be generated and viewed using the following methods:

Method 1: Using SQL*Plus Script

Oracle provides a built-in script to generate the AWR report:

@$ORACLE_HOME/rdbms/admin/awrrpt.sql

Steps:

  1. Connect to the database as SYSDBA:

    sqlplus / as sysdba
    
  2. Run the AWR report script:

    @$ORACLE_HOME/rdbms/admin/awrrpt.sql
    
  3. The script prompts for:

    • Report format: HTML or TEXT
    • Number of days: to list available snapshots
    • Beginning Snapshot ID
    • Ending Snapshot ID
    • Report filename
  4. The report is saved as an .html or .txt file and can be opened in a browser.


Method 2: Using Oracle Enterprise Manager (OEM)

  • Navigate to: Performance > AWR > AWR Report
  • Select the begin and end snapshot
  • Click Generate Report
  • View the report directly in the browser interface

Method 3: Using DBMS_WORKLOAD_REPOSITORY Package

SELECT output FROM TABLE(
  DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(
    l_dbid    => &dbid,
    l_inst_num => 1,
    l_bid     => &begin_snap,
    l_eid     => &end_snap
  )
);

Key Sections in an AWR Report:

  1. Report Summary - DB time, load profile
  2. Top 5 Timed Events - Major wait events
  3. SQL Statistics - Top SQL by CPU, elapsed time
  4. Instance Activity Statistics
  5. I/O Statistics
  6. Memory Statistics

Summary

FeatureDetail
Storage locationSYSAUX tablespace
Default snapshot interval60 minutes
Default retention8 days
Background processMMON
Report scriptawrrpt.sql

AWR is a critical tool for Oracle DBAs to diagnose, monitor, and tune database performance effectively.

Open this answer on its own page →

2081.1 · 5 marks

What is Oracle AWR? How AWR report is viewed in oracle? [5]

Show solved answer

Oracle AWR (Automatic Workload Repository)

What is Oracle AWR?

AWR (Automatic Workload Repository) is a built-in Oracle Database feature that automatically collects, processes, and maintains performance statistics for problem detection and self-tuning purposes.

Note: The following answer is based on standard Oracle Database documentation, as no specific curriculum notes were provided.

Key Characteristics of AWR:

  • AWR is part of Oracle's self-management framework, introduced in Oracle Database 10g.
  • It collects snapshots of database performance data at regular intervals (default: every 60 minutes).
  • Snapshots are stored in the SYSAUX tablespace and retained for a default period of 8 days.
  • It captures statistics such as:
    • SQL execution statistics
    • Wait events
    • System and session statistics
    • OS statistics
    • Memory usage

Purpose of AWR:

  • Identify performance bottlenecks
  • Support capacity planning
  • Enable trend analysis over time
  • Used by Oracle's ADDM (Automatic Database Diagnostic Monitor) for automated diagnosis

How AWR Report is Viewed in Oracle

AWR reports can be generated and viewed using the following methods:

Method 1: Using SQL*Plus Script

-- Connect as SYSDBA
sqlplus / as sysdba

-- Run the AWR report script
@$ORACLE_HOME/rdbms/admin/awrrpt.sql

Steps during execution:

  1. Choose report format: HTML or TEXT
  2. Specify the number of days to list snapshots
  3. Select the Begin Snapshot ID
  4. Select the End Snapshot ID
  5. Provide the output filename (e.g., awr_report.html)

Method 2: Using Oracle Enterprise Manager (OEM)

  1. Log in to Oracle Enterprise Manager (OEM)
  2. Navigate to: Performance > AWR > AWR Report
  3. Select the desired time period / snapshot range
  4. Click Generate Report
  5. View the report directly in the browser (HTML format)

Method 3: Using DBMS_WORKLOAD_REPOSITORY Package

-- Generate AWR report programmatically
SELECT output 
FROM TABLE(
    DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(
        l_dbid    => &dbid,
        l_inst_num => 1,
        l_bid     => &begin_snap,
        l_eid     => &end_snap
    )
);

AWR Report Contents:

SectionDescription
Report SummaryDB time, elapsed time, load profile
Wait EventsTop wait events during the period
SQL StatisticsTop SQL by CPU, elapsed time, I/O
Instance ActivityRedo, logical reads, physical reads
Memory StatisticsSGA, PGA usage
I/O StatisticsTablespace and file I/O

Summary

AWR is a powerful Oracle performance diagnostic tool that automatically captures workload data. Reports are primarily viewed via the awrrpt.sql script in SQL*Plus or through Oracle Enterprise Manager, helping DBAs analyze and resolve database performance issues.

Open this answer on its own page →

0 · 5 marks

What is Oracle AWR? How AWR report is viewed in oracle? [5]

Show solved answer

Oracle AWR (Automatic Workload Repository)

What is Oracle AWR?

AWR (Automatic Workload Repository) is a built-in Oracle Database feature that automatically collects, processes, and maintains performance statistics for problem detection and self-tuning purposes.

Note: The following answer is based on standard Oracle Database documentation, as no specific curriculum notes were provided.

Key Characteristics of AWR:

  • AWR is a repository of historical performance data stored in the SYSAUX tablespace of the Oracle database.
  • It collects snapshots of database performance statistics at regular intervals (default: every 60 minutes).
  • Snapshots are retained for a default period of 8 days, after which they are automatically purged.
  • It is managed by the MMON (Manageability Monitor) background process.

Data Collected by AWR:

CategoryExamples
Wait statisticsTop wait events, wait times
SQL statisticsHigh load SQL statements
System statisticsCPU usage, I/O, memory
Object statisticsSegment access, buffer cache hits
Time model statisticsDB time, parse time

Purpose of AWR:

  • Identify performance bottlenecks
  • Compare database performance between two time periods
  • Support Oracle Automatic Database Diagnostic Monitor (ADDM)
  • Assist DBAs in capacity planning and tuning

How AWR Report is Viewed in Oracle

AWR reports can be generated and viewed using the following methods:

Method 1: Using SQL*Plus Script

Oracle provides a built-in script to generate the AWR report:

-- Connect as SYSDBA
sqlplus / as sysdba

-- Run the AWR report script
@$ORACLE_HOME/rdbms/admin/awrrpt.sql

Steps during script execution:

  1. Choose report format: HTML or TEXT
  2. Enter the number of days to list snapshots
  3. Select the Begin Snapshot ID
  4. Select the End Snapshot ID
  5. Enter the report file name (e.g., awr_report.html)

Method 2: Using Oracle Enterprise Manager (OEM)

  1. Log in to Oracle Enterprise Manager (OEM)
  2. Navigate to: Performance --> AWR --> AWR Report
  3. Select the time period (begin and end snapshots)
  4. Click Generate Report
  5. View the report directly in the browser

Method 3: Using DBMS_WORKLOAD_REPOSITORY Package

-- Generate AWR report manually using PL/SQL
SELECT output 
FROM TABLE(
    DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(
        l_dbid    => &dbid,
        l_inst_num => 1,
        l_bid     => &begin_snap,
        l_eid     => &end_snap
    )
);

ViewDescription
DBA_HIST_SNAPSHOTLists all available snapshots
DBA_HIST_SYSSTATHistorical system statistics
DBA_HIST_SQL_PLANHistorical SQL execution plans
DBA_HIST_ACTIVE_SESS_HISTORYActive session history

Summary

AWR is a powerful Oracle performance monitoring tool that stores historical snapshots of database activity. DBAs use AWR reports to analyze performance trends, identify slow SQL queries, and diagnose database issues by comparing two snapshot periods using SQL*Plus scripts, OEM, or the DBMS_WORKLOAD_REPOSITORY package.

Open this answer on its own page →

SQL tuning definition and process

2081 · 5 marks

What is SQL Tuning? Explain SQL Tuning Process in Oracle? [5]

SQL Tuning (also called SQL Optimization) is the iterative process of improving the performance of SQL statements so that they execute faster, consume fewer resources (CPU, memory, I/O), and place less load on the database server. The goal is to ensure that the SQL optimizer chooses the most effi...

Open this answer on its own page →

Database auditing concepts

2080 · 5 marks

What is database auditing? Explain the standard auditing in oracle database. [5]

Database auditing is the process of monitoring and recording selected user database actions performed on a database. It involves tracking who accessed the database, what operations were performed, when they were performed, and from where they were performed. Auditing helps in: - Detecting unautho...

Open this answer on its own page →

2081.1 · 5 marks

Why do you think database auditing plays a significant role? Explain. [5]

Database auditing is the process of monitoring and recording all activities performed on a database, including who accessed the data, what operations were performed, when they were performed, and from where they were performed. --- - Auditing helps detect unauthorized access attempts, suspicious ...

Open this answer on its own page →

2081.1 · 5 marks

Write short notes on: a. Audit Trail b. SQL Tuning Advisor [5]

Note: Reference notes were not available for this topic. The following answer is based on standard Database Administration concepts as covered in BSc CSIT curriculum. --- An Audit Trail (also called an Audit Log) is a chronological record that provides documentary evidence of the sequence of acti...

Open this answer on its own page →

SQL Tuning Advisor usage

2080 · 5 marks

Explain how SQL tuning advisor can be used to tune your database. [5]

--- SQL Tuning Advisor is an Oracle Database built-in diagnostic tool that automatically analyzes SQL statements and provides recommendations to improve their performance. It acts as an expert system that examines problematic SQL and suggests tuning actions. --- - The DBA first identifies poorly ...

Open this answer on its own page →