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.
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 answerHide 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 TABLEorALTER TABLE) from conflicting with ongoing DML. - Oracle supports five modes of table-level locks:
| Mode | Abbreviation | Description |
|---|---|---|
| Row Share | RS (SS) | Allows concurrent access; prevents exclusive table lock |
| Row Exclusive | RX (SX) | Used during DML; prevents share and exclusive locks |
| Share | S | Allows only reads; prevents DML by others |
| Share Row Exclusive | SRX (SSX) | More restrictive than Share; only one transaction can hold it |
| Exclusive | X | Full exclusive access; no other DML or DDL allowed |
Lock Compatibility Matrix:
| RS | RX | S | SRX | X | |
|---|---|---|---|---|---|
| RS | Y | Y | Y | Y | N |
| RX | Y | Y | N | N | N |
| S | Y | N | Y | N | N |
| SRX | Y | N | N | N | N |
| X | N | N | N | N | N |
(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,CREATEoperations. 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.
- Exclusive DDL Lock: Acquired during
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 Statement | Row Lock | Table Lock Mode |
|---|---|---|
INSERT | Exclusive (X) on new row | RX |
UPDATE | Exclusive (X) on modified rows | RX |
DELETE | Exclusive (X) on deleted rows | RX |
SELECT | No lock | No 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 fornseconds 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:
| Mode | Meaning |
|---|---|
| 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 TABLEorDROP TABLErefers 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.
Oracle AWR overview
2081 · 5 marks
What is Oracle AWR? How AWR report is viewed in oracle? [5]
Show solved answerHide 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:
| Category | Examples |
|---|---|
| Wait statistics | Top wait events, wait times |
| SQL statistics | High-load SQL statements |
| System statistics | CPU usage, I/O, memory |
| Object statistics | Segment-level access info |
| Time model statistics | DB 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:
-
Connect to the database as SYSDBA:
sqlplus / as sysdba -
Run the AWR report script:
@$ORACLE_HOME/rdbms/admin/awrrpt.sql -
The script prompts for:
- Report format: HTML or TEXT
- Number of days: to list available snapshots
- Beginning Snapshot ID
- Ending Snapshot ID
- Report filename
-
The report is saved as an
.htmlor.txtfile 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:
- Report Summary - DB time, load profile
- Top 5 Timed Events - Major wait events
- SQL Statistics - Top SQL by CPU, elapsed time
- Instance Activity Statistics
- I/O Statistics
- Memory Statistics
Summary
| Feature | Detail |
|---|---|
| Storage location | SYSAUX tablespace |
| Default snapshot interval | 60 minutes |
| Default retention | 8 days |
| Background process | MMON |
| Report script | awrrpt.sql |
AWR is a critical tool for Oracle DBAs to diagnose, monitor, and tune database performance effectively.
2081.1 · 5 marks
What is Oracle AWR? How AWR report is viewed in oracle? [5]
Show solved answerHide 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:
- Choose report format: HTML or TEXT
- Specify the number of days to list snapshots
- Select the Begin Snapshot ID
- Select the End Snapshot ID
- Provide the output filename (e.g.,
awr_report.html)
Method 2: Using Oracle Enterprise Manager (OEM)
- Log in to Oracle Enterprise Manager (OEM)
- Navigate to: Performance > AWR > AWR Report
- Select the desired time period / snapshot range
- Click Generate Report
- 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:
| Section | Description |
|---|---|
| Report Summary | DB time, elapsed time, load profile |
| Wait Events | Top wait events during the period |
| SQL Statistics | Top SQL by CPU, elapsed time, I/O |
| Instance Activity | Redo, logical reads, physical reads |
| Memory Statistics | SGA, PGA usage |
| I/O Statistics | Tablespace 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.
0 · 5 marks
What is Oracle AWR? How AWR report is viewed in oracle? [5]
Show solved answerHide 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:
| Category | Examples |
|---|---|
| Wait statistics | Top wait events, wait times |
| SQL statistics | High load SQL statements |
| System statistics | CPU usage, I/O, memory |
| Object statistics | Segment access, buffer cache hits |
| Time model statistics | DB 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:
- Choose report format: HTML or TEXT
- Enter the number of days to list snapshots
- Select the Begin Snapshot ID
- Select the End Snapshot ID
- Enter the report file name (e.g.,
awr_report.html)
Method 2: Using Oracle Enterprise Manager (OEM)
- Log in to Oracle Enterprise Manager (OEM)
- Navigate to: Performance --> AWR --> AWR Report
- Select the time period (begin and end snapshots)
- Click Generate Report
- 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
)
);
Key AWR-Related Views:
| View | Description |
|---|---|
DBA_HIST_SNAPSHOT | Lists all available snapshots |
DBA_HIST_SYSSTAT | Historical system statistics |
DBA_HIST_SQL_PLAN | Historical SQL execution plans |
DBA_HIST_ACTIVE_SESS_HISTORY | Active 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.
SQL tuning definition and process
2081 · 5 marks
What is SQL Tuning? Explain SQL Tuning Process in Oracle? [5]
Database auditing concepts
2080 · 5 marks
What is database auditing? Explain the standard auditing in oracle database. [5]
2081.1 · 5 marks
Why do you think database auditing plays a significant role? Explain. [5]
2081.1 · 5 marks
Write short notes on: a. Audit Trail b. SQL Tuning Advisor [5]
SQL Tuning Advisor usage
2080 · 5 marks
Explain how SQL tuning advisor can be used to tune your database. [5]
Make Unit 8 stick
Practice BIT352 with flashcards & quizzes