• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to shrink a Temporary Tablespace datafile in Oracle

By admin

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. To do so follow the steps outlined below.

Shrinking datafile of a Temporary Tablespace

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  temporary tablespace TEMP1;

4. Drop the old tablespace:

SQL> drop tablespace temp including contents;

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.

Filed Under: oracle

Some more articles you might also be interested in …

  1. Oracle Database 12c New Feature – RMAN “RECOVER TABLE”
  2. Dynamic Oracle Net Server Tracing
  3. How to move ASM spfile to a shared device in RAC
  4. Extend rule sets by using factors in Oracle Database Vault
  5. How To Automate The Opening Of Pluggable Databases After The CDB Starts Up in Oracle 12c
  6. How to Set Multiple Events in INIT.ORA file
  7. Step By Step Guide To Create Physical Standby On Normal File System For ASM Primary using RMAN
  8. Common Init.ora Parameters and Unix, Linux Kernel Parameters and Relationship Between Them
  9. How to recreate Control file in Oracle Database
  10. How to relocate or move oracle database files using RMAN

You May Also Like

Primary Sidebar

Recent Posts

  • Failed to start LSB: Bring up/down networking – On restarting network service CentOS/RHEL (DHCP client)
  • How To Add Timestamps To dmesg Kernel Boot Log in CentOS/RHEL
  • How to disable ICMP redirects on CentOS/RHEL
  • What are Oracle Key Vault Roles
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary