You are on page 1of 2

SQL> CREATE TEMPORARY TABLESPACE temp2

2 TEMPFILE '/u02/oradata/TESTDB/temp2_01.dbf' SIZE 5M REUSE


3 AUTOEXTEND ON NEXT 1M MAXSIZE unlimited
4 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

Tablespace created.

SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;

Database altered.

SQL> DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;

Tablespace dropped.

SQL> CREATE TEMPORARY TABLESPACE temp


2 TEMPFILE '/u02/oradata/TESTDB/temp01.dbf' SIZE 500M REUSE
3 AUTOEXTEND ON NEXT 100M MAXSIZE unlimited
4 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

Tablespace created.

SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;

Database altered.

SQL> DROP TABLESPACE temp2 INCLUDING CONTENTS AND DATAFILES;

Tablespace dropped.

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';

You might also like