dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/oracle/#73
Script #73
oracle
Storageread-onlyMin Version: 11g

Sessions Consuming Oracle TEMP Tablespace

Lists sessions and SQL consuming TEMP space. Finds the source of ORA-01652 errors.

#temp#sort#v$tempseg_usage
oracle · sql
SELECT s.sid, s.serial#, s.username, s.program, u.tablespace, u.segtype,
       ROUND(u.blocks * ts.block_size / 1048576, 1) AS temp_mb, u.sql_id
FROM   v$tempseg_usage u
JOIN   v$session s ON s.saddr = u.session_addr
JOIN   dba_tablespaces ts ON ts.tablespace_name = u.tablespace
ORDER  BY u.blocks DESC;
Operational Notes & Remediation Guidance

Verify in a staging environment prior to running in production. This is a read-only diagnostic query; it does not acquire exclusive locks.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 11g).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.