DBAtlas · Database operations atlas

View long-running queries / sessions

OracleSessions & Processes

Command

-- Active, long-running SQL:
SELECT s.sid, s.serial#, s.username, s.status,
       s.last_call_et AS seconds_active,
       s.sql_id, q.sql_text,
       s.event, s.machine, s.program
FROM   v$session s
  LEFT JOIN v$sql q ON q.sql_id = s.sql_id
                   AND q.child_number = s.sql_child_number
WHERE  s.type = 'USER'
  AND  s.status = 'ACTIVE'
  AND  s.last_call_et > 60
ORDER BY s.last_call_et DESC;

-- Long operations with percentage progress:
SELECT sid, serial#, opname, sofar, totalwork,
       ROUND(sofar/NULLIF(totalwork,0)*100,1) AS pct, time_remaining
FROM   v$session_longops
WHERE  sofar < totalwork ORDER BY start_time DESC;

What it does

Lists active sessions running longer than 60 seconds and the progress of long-running batch operations.

When to use it

On slowness complaints, to find which query is keeping the system busy.

Caution

last_call_et is the time since the last call; it can also be large for an idle session, so the status='ACTIVE' filter matters. Query only; no risk.

Open in DBAtlas →

Related