Perth, Australia
+ (61) 417713124

Script – Temporary tablespace usage

  • Posted by Arjun Raja
  • On June 30, 2009

Listing of temp segments.

SELECT A.tablespace_name tablespace, D.mb_total,
SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total – SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM v$sort_segment A,
SELECT, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
FROM v$tablespace B, v$tempfile C
WHERE B.ts#= C.ts#
GROUP BY, C.block_size
) D
WHERE A.tablespace_name =
GROUP by A.tablespace_name, D.mb_total;

Temp segment usage per session.

SELECT S.sid || ‘,’ || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,
P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) statements
FROM v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE T.session_addr = S.saddr
AND S.paddr = P.addr
AND T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY sid_serial;



  • Oct 9 2009
Hi Gavin, Thanks for wonderful sql statements to find temp segment usage per session. I would like to draw your attention for firet sql statement.When i run first sql statement in my testing enviroment. It was throwing following error message ORA-00911 "Invalid Character".I removed minus sign and put it again.After this it worked fine. I was able to find culprit session with use of second sql statement. Good work keep it up. Jaimin
Ranvijay kumar
  • Feb 16 2017
Nice Thanks
  • Dec 24 2018
Great article. It covers almost all the queries related to temporary tablespace

Leave Reply

Your email address will not be published. Required fields are marked *