ORASOLU TOOLBOX · HIGH AVAILABILITY

RAC Session Distribution

Practical Oracle RAC SQL for reviewing session distribution, active workload, services, client programs and waits across instances.

ORASOLU TOOLBOX · HIGH AVAILABILITY

Understand where RAC workload is running

Review session placement by instance and service, then correlate active workload with client programs and current wait activity.

01 · SESSION DISTRIBUTION

Review sessions across RAC instances

See how current database sessions are distributed across services and RAC instances.

SELECT
    inst_id,
    service_name,
    COUNT(*) AS session_count
FROM gv$session
WHERE service_name IS NOT NULL
GROUP BY
    inst_id,
    service_name
ORDER BY
    service_name,
    inst_id;
02 · ACTIVE SESSIONS

Find active sessions by instance

Compare currently active sessions across RAC instances to identify where foreground activity is running.

SELECT
    inst_id,
    COUNT(*) AS active_sessions
FROM gv$session
WHERE status = 'ACTIVE'
GROUP BY inst_id
ORDER BY active_sessions DESC;
03 · SERVICE ACTIVITY

Review active sessions by service

Identify services with the largest number of active sessions across the cluster.

SELECT
    service_name,
    COUNT(*) AS active_sessions
FROM gv$session
WHERE status = 'ACTIVE'
  AND service_name IS NOT NULL
GROUP BY service_name
ORDER BY active_sessions DESC
FETCH FIRST 20 ROWS ONLY;
04 · INSTANCE WORKLOAD

Compare workload by instance

Summarize active, inactive and total sessions for each RAC instance.

SELECT
    inst_id,
    COUNT(*) AS total_sessions,
    SUM(CASE WHEN status = 'ACTIVE' THEN 1 ELSE 0 END)
        AS active_sessions,
    SUM(CASE WHEN status = 'INACTIVE' THEN 1 ELSE 0 END)
        AS inactive_sessions
FROM gv$session
GROUP BY inst_id
ORDER BY inst_id;
05 · CLIENT DISTRIBUTION

Review service and client distribution

Identify which client programs are generating sessions through each RAC service.

SELECT
    service_name,
    program,
    COUNT(*) AS session_count
FROM gv$session
WHERE service_name IS NOT NULL
GROUP BY
    service_name,
    program
ORDER BY session_count DESC
FETCH FIRST 20 ROWS ONLY;
06 · SESSION WAITS

Review waits across RAC sessions

Inspect active sessions that are currently waiting and identify the instance, service and wait event.

SELECT
    inst_id,
    service_name,
    sid,
    serial#,
    username,
    event,
    wait_class,
    seconds_in_wait
FROM gv$session
WHERE status = 'ACTIVE'
  AND wait_class <> 'Idle'
ORDER BY seconds_in_wait DESC
FETCH FIRST 20 ROWS ONLY;

ORASOLU TOOLBOX · HIGH AVAILABILITY

Session distribution provides workload context.

A session count alone does not describe application performance. Combine instance and service distribution with session state, SQL, wait events and client information when investigating RAC workload.

Oracle documents GV$SESSION as the global view of current session information. INST_ID identifies the RAC instance from which each row was obtained.