Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Shrinking a Locally Managed Temporary Tablespace

Gerrit HaaseNov 20 2012 — edited Apr 25 2013
So, even thoguh the documentation is pretty clear about how to use this feature, I cannot get it to do what I expect it to do for me.

And that would be shrinking the tempfile ;)

Now lets face it, I have a large tempfile and want to resize it without restarting the database:

C:\Users\Administrator>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Di Nov 20 05:49:59 2012

Copyright (c) 1982, 2010, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Release 11.2.0.2.0 - 64bit Production

SQL> select file_name
, ceil(bytes / 1024 / 1024) "size MB"
from dba_temp_files
/

FILE_NAME size MB
---------------------------------------------------------------------- ------------
R:\MXVC01\TEMP01.DBF 31,231

SQL> select su.username
, ses.sid
, ses.serial#
, su.tablespace
, ceil((su.blocks * dt.block_size) / 1048576) MB
from v$sort_usage su
, dba_tablespaces dt
, v$session ses
where su.tablespace = dt.tablespace_name
and su.session_addr = ses.saddr
/

USERNAME SID SERIAL# TABLESPACE MB
--------------- ---------- ---------- ------------------------------- --------
VPXADMIN 15 15 TEMP 14
VPXADMIN 17 5 TEMP 1,203
VPXADMIN 17 5 TEMP 1
VPXADMIN 18 3 TEMP 7
VPXADMIN 19 3 TEMP 1
VPXADMIN 144 3 TEMP 1
VUMADMIN 156 2597 TEMP 1

7 rows selected.

Or this one:

SQL> select tablespace_size/1024/1024 "tablespace_size mb"
, allocated_space/1024/1024 "allocated_space mb"
, free_space/1024/1024 "free_space mb"
from dba_temp_free_space
/

tablespace_size mb allocated_space mb free_space mb
------------------ ------------------ -------------
31230,9922 1228,99219 30002



Documetation from here: http://docs.oracle.com/cd/E11882_01/server.112/e25494/tspaces007.htm#ADMIN12353


+"Shrinking a Locally Managed Temporary Tablespace+
+Large sort operations performed by the database may result in a temporary tablespace growing and occupying a considerable amount of disk space. After the sort operation completes, the extra space is not released; it is just marked as free and available for reuse. Therefore, a single large sort operation might result in a large amount of allocated temporary space that remains unused after the sort operation is complete. For this reason, the database enables you to shrink locally managed temporary tablespaces and release unused space.+

+You use the SHRINK SPACE clause of the ALTER TABLESPACE statement to shrink a temporary tablespace, or the SHRINK TEMPFILE clause of the ALTER TABLESPACE statement to shrink a specific tempfile of a temporary tablespace. Shrinking frees as much space as possible while maintaining the other attributes of the tablespace or tempfile. The optional KEEP clause defines a minimum size for the tablespace or tempfile.+

+Shrinking is an online operation, which means that user sessions can continue to allocate sort extents if needed, and already-running queries are not affected.+

+The following example shrinks the locally managed temporary tablespace lmtmp1 to a size of 20M.+

+ALTER TABLESPACE lmtemp1 SHRINK SPACE KEEP 20M;+

+The following example shrinks the tempfile lmtemp02.dbf of the locally managed temporary tablespace lmtmp2. Because the KEEP clause is omitted, the database attempts to shrink the tempfile to the minimum possible size.+

+ALTER TABLESPACE lmtemp2 SHRINK TEMPFILE '/u02/oracle/data/lmtemp02.dbf';"+



OK, lets do it:

SQL> alter tablespace temp shrink tempfile 'R:\MXVC01\TEMP01.DBF';
alter tablespace temp shrink tempfile 'R:\MXVC01\TEMP01.DBF'
*
ERROR at line 1:
ORA-03214: File Size specified is smaller than minimum required


It seems there is a bug? Should I report it, or is it the expected behaviour?

Now lets try this one:

SQL> alter tablespace temp shrink tempfile 'R:\MXVC01\TEMP01.DBF' keep 2048M;

Tablespace altered.

SQL> select file_name
, ceil(bytes / 1024 / 1024) "size MB"
from dba_temp_files
/

FILE_NAME size MB
---------------------------------------------------------------------- ------------
R:\MXVC01\TEMP01.DBF 31,231

So .... this lasts about *10 minutes*, and nothing changes?

It seems there is a bug? Should I report it, or is it the expected behaviour?


Could someone enlighten me, what this SHRINK is actually doing?
Is it worth to report this as bug, if not a software bug it is at least a documentation bug because it doesn't mention under which conditions it is working?


P.S.: OMG the posting looks terrible, who's the one to blame for this forum software where it is not possible to use fixed size fonts, or format paragraphs as code, or what about the fact that the forum software is using default SQLPlus output as META for some graphical lines?

Isn't this the forum for Oracle Database users?

Edited by: Gerrit Haase on 20.11.2012 13:44
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 23 2013
Added on Nov 20 2012
18 comments
2,806 views