The database in our organisation have around 350 MB
of Temporary tablespace. I often run the query
select tablespace_name , sum(bytes)/(1024* 1024)
from dba_free_space group by tablespace_name
I always see the tempory tablespace having less than
5MB of Free space even when there is no transactions for
a long time. As far as I have understood temporary
tablespace are used, mostly for transactions requiring
sort operation that does not fit in SGA memory and is
released when the transaction is complete.
My questions are
Is it something normal ?
Does it have any negative impact on the performance ?
If so then how to release space other than dropping
and recreating the temporary tablespace ?
My storage parametes for temporary tablespace are
Inital 400 K , Next 400 K , Pctincrease 0 , & AutoExtend enabled.
Can you bounce your DB and then check the free space ? Also what is the max_extents of your temp tablespace ?
also check out your sort_area_size init.ora parameter.
You are right about temp tablespaces and they are used in sort operations as well as index rebuilds.
Default Storage specification for your TEMPORARY tablespace:
Use the following guidelines to specify DEFAULT STORAGE:
Set INITIAL=NEXT.Since a process always writes data equal to
SORT_AREA_SIZE to a temporary segment, a good value for the extent
size is (n*s + b)
where: n is a positive integer
s is the value of SORT_AREA_SIZE initialization parameter
b is the value of DB_BLOCK_SIZE initialization parameter
Using this value optimizes temporary segment usage by allowing
sufficient space for a header block and multiple sort run data to be
stored in each extent.
Specify a PCTINCREASE of zero to ensure that all extents are of the
The MAXEXTENTS parameter only affects a temporary segment if the
tablespace is a PERMANENT tablespace."
here is the maths for sizing extents from metalink
You calculate the estimated space for TEMPORARY segments as you would for
any other tables. The worse case will to the same size as table A (the 4
million row table). If the GROUP BY of 26 columns is a subset of table A,
then it will be smaller. To calculate do the following:
So for 10000 rows, #blocks = 10000 / 160
= 62 blocks
For your 27 column group by you will need to come up with a row length.
This may be larger than the 2048 byte block size. Do the following
assume avg row size (which note includes space for column overhead and row
flags) is 4000 bytes. Then
#r/b = 1768 - 2x - 4000x
--> 4002x = 1768
x = 1768 / 4002
x = .441
--> 1 / .441 = # blocks/r
2. How does the sum clause operate in this situation and how much space would
it need? (the size of the table, etc..)
I doubt that the sum function will need much space, it will be a running
total after the group by is computed off the temporary segment.
3. Same as #2 but with group by's. I guess what he is hoping for is a high
level algorithm as to what operations are involved and how they are
Use the formulas outlined under Q1 above. Anytime you use a GROUP BY,
ORDER BY, or join tables, you will need a sort area size and if the
sort/join cannot be computed in memory (number of rows in table will
not all fit into the memory allocated by SORT_AREA_SIZE), a temporary
segment will be created.
Your problem is very normal and i think julian's suggestion is your best choice. When temporary tablespace is created with TEMPORARY type, the space will not be released until the instance is shutdown. If it is created with PERMANENT type, then SMON will do the cleanup. However, if there are large number of sort segments in your temporary tablepace, SMON may take more time to do the housekeep and your perfermance maybe affected. So the best choice is create locally managed temporary tablespace which benifits of faster cleanup and reduces contention CPU usage by SMON.