Skip to content

Parallel Execution Session Monitor (vpx.sql)

This script provides detailed monitoring of Oracle parallel execution sessions, showing the relationship between query coordinators (QC) and their parallel slaves, along with degree of parallelism information.

col username for a12
col "QC SID" for A6
col SID for A6
col "QC/Slave" for A10
col "Requested DOP" for 9999
col "Actual DOP" for 9999
col "slave set" for A10
col sql_hash_value format 9999999999999999 heading 'SQL Hash Value'
set lines 132
select
decode(px.qcinst_id,NULL,username,
' - '||lower(substr(s.program,length(s.program)-4,4) ) ) "Username",
decode(px.qcinst_id,NULL, 'QC', '(Slave)') "QC/Slave" ,
to_char( px.server_set) "Slave Set",
to_char(s.sid) "SID",
decode(px.qcinst_id, NULL ,to_char(s.sid) ,px.qcsid) "QC SID",
px.req_degree "Requested DOP",
px.degree "Actual DOP",
s.SQL_HASH_VALUE
from
v$px_session px,
v$session s
where px.sid=s.sid (+)
and px.serial#=s.serial#
order by 5 , 1 desc
/

This script monitors Oracle’s parallel execution infrastructure by:

  • Identifying Query Coordinators: Shows which sessions are coordinating parallel operations
  • Mapping Parallel Slaves: Displays which slave processes belong to each coordinator
  • Showing DOP Information: Compares requested vs. actual degree of parallelism
  • Grouping by Operation: Orders results by coordinator to group related slaves
  • Tracking SQL Operations: Shows SQL hash values for correlation
-- Monitor current parallel operations
@vpx.sql
-- Run during heavy parallel workload for best results
-- Can be run repeatedly to monitor parallel execution patterns
  • SELECT privilege on V$PX_SESSION
  • SELECT privilege on V$SESSION
  • Typically requires DBA role or SELECT_CATALOG_ROLE
Username QC/Slave Slave Set SID QC SID Requested DOP Actual DOP SQL Hash Value
------------ ---------- ---------- ------ ------ ------------- ----------- ----------------
SALES_USER QC 156 156 4 4 2034815321748235
- ora (Slave) 1 157 156 4 4 2034815321748235
- ora (Slave) 1 158 156 4 4 2034815321748235
- ora (Slave) 2 159 156 4 4 2034815321748235
- ora (Slave) 2 160 156 4 4 2034815321748235
HR_USER QC 203 203 8 6 8901234567823456
- ora (Slave) 1 204 203 8 6 8901234567823456
- ora (Slave) 1 205 203 8 6 8901234567823456
- ora (Slave) 1 206 203 8 6 8901234567823456
- ora (Slave) 2 207 203 8 6 8901234567823456
- ora (Slave) 2 208 203 8 6 8901234567823456
- ora (Slave) 2 209 203 8 6 8901234567823456
ColumnDescription
UsernameUser running the query (QC) or ’- ora’ for slave processes
QC/SlaveRole: ‘QC’ for Query Coordinator, ‘(Slave)’ for parallel slaves
Slave SetSlave set number (1 or 2) for organizing parallel slaves
SIDSession ID of this particular session
QC SIDSession ID of the Query Coordinator for this group
Requested DOPDegree of Parallelism requested by the query
Actual DOPActual Degree of Parallelism allocated by Oracle
SQL Hash ValueHash value of the SQL statement being executed
  • Role: Coordinates the parallel execution and merges results
  • Identification: Shows actual username and ‘QC’ in QC/Slave column
  • Resources: Uses minimal CPU, mainly for coordination
  • Role: Execute portions of the SQL statement in parallel
  • Identification: Show ’- ora’ username and ‘(Slave)’ designation
  • Organization: Grouped into slave sets (typically 1 and 2)
  • Resources: Perform the actual work (scans, joins, sorts)
  • Set 1: First group of parallel slaves
  • Set 2: Second group of parallel slaves (for operations requiring redistribution)
  • Usage: Complex operations may use both sets for different phases
-- Run this script during heavy parallel workload
@vpx.sql
-- Check if DOP is being downgraded
SELECT DISTINCT qcsid, req_degree, degree
FROM v$px_session
WHERE req_degree != degree;
-- Find queries with reduced parallelism
SELECT px.qcsid, s.username, s.sql_id,
px.req_degree as requested,
px.degree as actual,
px.req_degree - px.degree as shortfall
FROM v$px_session px, v$session s
WHERE px.sid = s.sid
AND px.qcinst_id IS NULL -- QC only
AND px.req_degree > px.degree;
-- Check recent parallel execution from AWR
SELECT sql_id, plan_hash_value,
px_servers_requested, px_servers_allocated,
executions, elapsed_time_delta/1000000 as elapsed_sec
FROM dba_hist_sqlstat
WHERE px_servers_requested > 1
AND snap_id BETWEEN &start_snap AND &end_snap
ORDER BY elapsed_time_delta DESC;
-- Check what parallel slaves are waiting for
SELECT s.sid, s.username, s.event, s.state,
s.seconds_in_wait, px.server_set
FROM v$session s, v$px_session px
WHERE s.sid = px.sid
AND px.qcinst_id IS NOT NULL -- Slaves only
AND s.status = 'ACTIVE'
ORDER BY px.qcsid, px.server_set, s.sid;
-- Analyze why DOP was reduced
SELECT parameter, value, isdefault
FROM v$parameter
WHERE name IN (
'parallel_max_servers',
'parallel_servers_target',
'parallel_degree_limit',
'parallel_adaptive_multi_user'
);
-- Check parallel server usage
SELECT servers_started, servers_shutdown,
servers_highwater, servers_cleaned_up
FROM v$pq_sysstat
WHERE statistic = 'Servers Started';
-- Check if hitting parallel server limits
SELECT * FROM v$resource_limit
WHERE resource_name LIKE '%parallel%';
-- Get SQL text for parallel operations
SELECT DISTINCT s.sql_id, s.sql_text
FROM v$session s, v$px_session px
WHERE s.sid = px.sid
AND px.qcinst_id IS NULL -- QC only
AND s.sql_text IS NOT NULL;
  • CPU-bound operations: DOP = number of CPU cores
  • I/O-bound operations: DOP can exceed CPU cores
  • Mixed workloads: Consider parallel_adaptive_multi_user=true
  • Run during peak hours: Get realistic parallel usage patterns
  • Track DOP downgrades: Indicates resource constraints
  • Monitor wait events: Identify parallel execution bottlenecks
  • Check skew: Ensure work is evenly distributed
  • DOP Downgrade: Insufficient parallel servers available
  • Skewed Distribution: Uneven work distribution among slaves
  • Interconnect Bottlenecks: High parallel execution waits
  • Memory Pressure: PGA memory limits affecting parallel operations

This script works well with:

-- Create a monitoring script for parallel execution
-- Save as monitor_parallel.sql
SET PAGESIZE 1000
SET LINESIZE 150
COLUMN timestamp FORMAT A20
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') as timestamp,
COUNT(DISTINCT qcsid) as active_parallel_queries,
SUM(CASE WHEN qcinst_id IS NULL THEN 1 ELSE 0 END) as coordinators,
SUM(CASE WHEN qcinst_id IS NOT NULL THEN 1 ELSE 0 END) as slaves,
AVG(degree) as avg_actual_dop,
AVG(req_degree) as avg_requested_dop
FROM v$px_session;
-- Detailed parallel session information
@vpx.sql

This script is essential for DBAs managing environments with heavy parallel processing workloads and provides crucial insights into Oracle’s parallel execution infrastructure.