ORASOLU TOOLBOX · PERFORMANCE

Performance & Diagnostics

Practical Oracle performance scripts, diagnostics queries and investigation resources for everyday database troubleshooting.

ORASOLU TOOLBOX · PERFORMANCE

Practical performance diagnostics for everyday database work

A collection of reusable queries for investigating waits, active sessions, resource pressure, long-running operations and monitored SQL.

01 · SYSTEM WAITS

Find the highest system wait events

Start with instance-level wait time to identify where foreground activity is spending time.

SELECT
    event,
    wait_class,
    total_waits,
    ROUND(time_waited_micro / 1000000, 2) AS wait_seconds,
    ROUND(
        CASE
            WHEN total_waits > 0
            THEN time_waited_micro / total_waits / 1000
        END,
        2
    ) AS avg_wait_ms
FROM v$system_event
WHERE wait_class <> 'Idle'
ORDER BY time_waited_micro DESC
FETCH FIRST 20 ROWS ONLY;
02 &middot; WAIT CLASSES

Review wait activity by class

Use wait classes to see whether the current pressure is concentrated in User I/O, Concurrency, Commit or another class.

SELECT
    wait_class,
    total_waits,
    ROUND(time_waited_micro / 1000000, 2) AS wait_seconds,
    ROUND(
        CASE
            WHEN total_waits > 0
            THEN time_waited_micro / total_waits / 1000
        END,
        2
    ) AS avg_wait_ms
FROM v$system_wait_class
WHERE wait_class <> 'Idle'
ORDER BY time_waited_micro DESC;
03 &middot; ACTIVE SESSIONS

See active sessions and current waits

Combine session state, wait information and SQL identifiers to identify what is active right now.

SELECT
    sid,
    serial#,
    username,
    status,
    event,
    wait_class,
    state,
    seconds_in_wait,
    sql_id,
    blocking_session
FROM v$session
WHERE type = 'USER'
  AND status = 'ACTIVE'
ORDER BY seconds_in_wait DESC
FETCH FIRST 30 ROWS ONLY;
04 &middot; LONG OPERATIONS

Find long-running database operations

Inspect operations with measurable progress to understand what is running for an extended period.

SELECT
    sid,
    serial#,
    opname,
    target,
    sofar,
    totalwork,
    units,
    start_time,
    elapsed_seconds,
    time_remaining
FROM v$session_longops
WHERE totalwork > 0
  AND sofar < totalwork
ORDER BY elapsed_seconds DESC
FETCH FIRST 20 ROWS ONLY;
05 &middot; RESOURCE LIMITS

Check current resource utilization

Compare current and maximum utilization against configured limits for key database resources.

SELECT
    resource_name,
    current_utilization,
    max_utilization,
    limit_value
FROM v$resource_limit
ORDER BY resource_name;
06 &middot; SQL MONITOR

Review monitored SQL executions

Use Real-Time SQL Monitoring data to inspect recent executions and their elapsed time, CPU and I/O activity.

SELECT
    m.sql_id,
    m.sql_exec_start,
    m.status,
    ROUND(m.elapsed_time / 1000000, 2) AS elapsed_seconds,
    ROUND(m.cpu_time / 1000000, 2) AS cpu_seconds,
    m.buffer_gets,
    m.disk_reads,
    SUBSTR(s.sql_text, 1, 1000) AS sql_text
FROM v$sql_monitor m
LEFT JOIN v$sql s
    ON s.sql_id = m.sql_id
WHERE m.sql_exec_start >= SYSDATE - 1/24
ORDER BY m.elapsed_time DESC
FETCH FIRST 20 ROWS ONLY;
Diagnostic workflow:establish the symptom, identify the dominant waits or active sessions, correlate the session with SQL and resources, then investigate the specific operation. Real-Time SQL Monitoring is an Oracle feature with licensing and configuration considerations in the target environment.