← Space Management
Oracle · Space Management

How to check temp tablespace usage in Oracle

Check Oracle temp tablespace usage and which sessions are using temp right now.

Tested on11g12c19c21c23ai26ai

Temp tablespace totals from the space header, plus the sessions using temp right now so you can find a runaway sort or hash join.

-- Temp tablespace usage
SELECT th.tablespace_name,
       ROUND(SUM(tf.bytes)/1024/1024)      AS total_mb,
       ROUND(SUM(th.bytes_used)/1024/1024) AS used_mb,
       ROUND(SUM(th.bytes_free)/1024/1024) AS free_mb
FROM   v$temp_space_header th
       JOIN dba_temp_files tf ON tf.file_id = th.file_id
GROUP  BY th.tablespace_name
ORDER  BY th.tablespace_name;

-- Sessions using temp right now
SELECT s.username, s.sid, s.serial#, u.tablespace,
       ROUND(u.blocks * (SELECT value FROM v$parameter WHERE name = 'db_block_size') / 1024 / 1024) AS mb
FROM   v$sort_usage u
       JOIN v$session s ON s.saddr = u.session_addr
ORDER  BY u.blocks DESC;
spacetemptablespacev$sort_usage