KB · Oracle Database · Script

Top 10 sessions by I/O right now (v$sesstat)

Oracle Database · Script · Verified on Oracle 11.2 and 23ai · Updated 2026-12-03

When the database is busy and you need to know who's doing it, this ranks active user sessions by the sum of consistent gets, db block gets, physical reads and db block changes, and shows the top ten with everything you need to identify them, including the OS process ID (SPID) to find them in top.

Usage

SQL> @t10s.sql -1
SQL> @t10s.sql 10

The argument filters the top ten by how long each session's current call has run, in whole minutes: only sessions above it are shown. 0 means at least a minute; use -1 to see all ten.

t10s.sqlMIT · Download ·
-- t10s.sql: top 10 active sessions by logical and physical I/O
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/top-sessions-by-io/
--
-- Usage: @t10s.sql <minutes>
--        @t10s.sql 10     only sessions active for more than 10 minutes

alter session set nls_date_format='RRRR-DD-MON HH24:MI';

set lines 256
set trims on

col sid_serial        format a12         heading "Sid,Serial"
col USERNAME          format a8 trunc    heading "User"
col MACHINE           format a10 trunc   heading "Machine"
col PROCESS           format a10         heading "PROCESS"
col spid              format a10         heading "SPID"
col OSUSER            format a10 trunc   heading "OS-User"
col logon             format a15         heading "Login Time"
col idle              format a8          heading "Idle"
col status            format a1          heading "STS"
col lockwait          format a1          heading "L|W"
col module            format a35 trunc   heading "Module"

select top_ten.tot_value
,      chr(39)||s.sid||','||s.serial#||chr(39) sid_serial
,      s.username
,      SUBSTR(s.status,1,1) status
,      s.lockwait
,      s.osuser
,      s.process
,      p.spid
,      s.machine
,      to_char(s.logon_time,'DDth HH24:MI:SS') logon
,      floor(last_call_et/60) ACTIVE_MIN
,      s.program||' '||s.module||' '||s.action  module
from
   (select tot_value
    ,      sid
    from
        (select sum(stat.value) tot_value
        ,      s.sid
        from v$sesstat stat
        ,    v$statname sname
        ,    v$session s
        where s.sid = stat.sid
                and   stat.STATISTIC# = sname.STATISTIC#
        and   sname.name IN( 'consistent gets', 'db block gets'
                           , 'physical reads' , 'db block changes')
        and   s.type <> 'BACKGROUND'
        and   s.schemaname <> 'SYS'
        and   s.status = 'ACTIVE'
        group by s.sid
        order by tot_value desc)
    where  rownum < 11)       top_ten
, v$session    s
, v$process    p
where top_ten.sid = s.sid
and   floor(last_call_et/60) > &&1
and   s.paddr = p.addr
order by 1 desc;

undefine 1

curl -O https://hashjoin.com/kb/oracle/top-sessions-by-io/t10s.sql

Reading the output

TOT_VALUE is the I/O total. ACTIVE_MIN is how long the session's current call has been running. A session at the top with a high ACTIVE_MIN is a long-running statement worth a look: take its SID to drill into one session for its SQL.

Gotchas

What it reads

v$sesstat v$statname v$session v$process

Tired of fixing the same thing twice?

HASHJOIN turns the checks and fixes your on-call runs by hand into tooling that gives the same answer every time. Fixed scope, and you own all of the code.