How to Shrink the Datafile of Temporary Tablespace

In this Document
  Goal
  Solution


 

Applies to:

Oracle Server - Enterprise Edition - Version: 8.1.7.4 to 11.2.0.2 - Release: 8.1.7 to 11.2
Information in this document applies to any platform.
***Checked for relevance on 16-Dec-2011***

Goal

The database has a program which performs a huge sort operation (e.g. end of the year reporting process).  This may cause the TEMP tablespace to grow and occupy most of the space on the file system.

In this example, the report process may run once or twice a year and there is no need to maintain/keep a huge tempfile.

The TEMP tablespace was created with datafiles (dictionary managed tablespace temporary) as AUTOEXTEND ON MAXSIZE UNLIMITED to avoid the Error: 
  ORA-1652 Text: unable to extend temp segment by %s in tablespace %s.

Attempts have been made to "alter database datafile .. resize" which fail with:  

Error: ORA 3297 : file contains <> blocks of data beyond requested RESIZE value

You want to shrink the datafile to utilize the disk space for other tablespaces or other purposes.


Solution

1)  Create a new temporary tablespace with desired smaller size:

SQL> create temporary tablespace TEMP1 tempfile 'c:\temp01.dbf' size 100M extent management
local uniform size 128K;



2)  If the original tablespace is a default temporary tablespace, set the new tablespace as default temporary tablespace for all users in the database:

SQL> alter database default temporary tablespace TEMP1;



3)  If necessary, explicitly re-assign specific users to the new tablespace:

SQL> alter user <username> temporary tablespace TEMP1;



4) Drop the old tablespace:

SQL> drop tablespace temp including contents;


Note:
In Oracle 9i and higher, the drop command can also drop datafiles at OS level:

SQL> drop tablespace temp INCLUDING CONTENTS AND DATAFILES;



 

NOTE:
Temporary tablespaces should appear "full" after a while in a normally running database.  
Extents are allocated once and then managed by the system. Rather than doing the rather expensive operation of "space management" (data dictionary updates), the system will allocate an extent in TEMP and then keep it and manage it itself.
This is normal and to be expected and is not an indication that there is a lack of temporary space.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值