Temp Space Usage in Oracle
Categories: Database Administration, Information Technology, OracleDon’t just grow your TEMP tablespace, examine it!
Recently I was facing a problem not unusual in high-throughput Oracle databases… a full TEMP tablespace. I’ve run into this before and it can be frustrating trying to determine where all the space went. In this case we are using a 6 gig temporary tablespace and for some reason it was full.
Well, all the gorey details aside, one thing that helped me determine what was going on was this tip from Oracle which contains code to examine who is using your temporary tablespace up.
By running the following command (reprinted here for easy reference and because there are nasty line breaks on Oracle’s site) you get a fairly good idea of the usage of temporary space by tablespace, username and amount used.
set pagesize 10000
set linesize 133
column tablespace format a15 heading 'Tablespace Name'
column segfile# format 9,999 heading 'File|ID'
column spid format 9,999 heading 'Unix|ID'
column segblk# format 999,999,999 heading 'Block|ID'
column size_mb format 999,999,990.00 heading "Mbytes|Used"
column username format a15
column program format a15
select b.tablespace, b.segfile#, b.segblk#,
round(((b.blocks*p.value)/1024/1024),2) size_mb,
a.sid, a.serial#, a.username, a.osuser, a.program, a.status
from v$session a, v$sort_usage b, v$process c, v$parameter p
where p.name='db_block_size' and a.saddr = b.session_addr
and a.paddr=c.addr
order by b.tablespace,b.segfile#,b.segblk#,b.blocks;
While I consider rewriting this into a somewhat more palatable form, on the occasion that I need this I don’t typically care about nice formatting… I just want the numbers in a hurry.
To clear up unused TEMP space Oracle also recommends running this as sysdba:
alter tablespace temp default storage(pctincrease 0);
4 Responses to “Temp Space Usage in Oracle”
-
Sridhar Says:
April 27th, 2006 at 2:52 pmMr.Jon,
Should you have mentioned on which Oracle Version your Alter Tablespace syntax would work?Thanks for your article though.
Sridhar Reddy
-
Jon Says:
April 29th, 2006 at 8:59 amGood point Sridhar. This was written for Oracle 9iR2. Might work on others, but no promises.
Jon
-
trieder Says:
May 15th, 2008 at 7:26 amIs there any possiblity to see the historical temp usage?
-
Jay Says:
July 6th, 2010 at 3:55 pmGood and handy script. Thanks.

