Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 493541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:24:56+00:00 2026-05-13T05:24:56+00:00

How can we shrink temp tablespace in oracle? And why it is increasing so

  • 0

How can we shrink temp tablespace in oracle? And why it is increasing so much like upto 25 GB since there is only one schema in the database for the application and data table space size is 2 GB and index table space size is 1 GB used.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:24:57+00:00Added an answer on May 13, 2026 at 5:24 am

    Oh My Goodness! Look at the size of my temporary table space!
    Or… how to shrink temporary tablespaces in Oracle.

    Yes I ran a query to see how big my temporary tablespace is:

    SQL> SELECT tablespace_name, file_name, bytes
    2  FROM dba_temp_files WHERE tablespace_name like 'TEMP%';
    
    TABLESPACE_NAME   FILE_NAME                                 BYTES
    ----------------- -------------------------------- --------------
    TEMP              /the/full/path/to/temp01.dbf     13,917,200,000
    

    The first question you have to ask is why the temporary tablespace is so large.
    You may know the answer to this off the top of your head. It may be due to a
    large query that you just run with a sort that was a mistake (I have done that
    more than once.) It may be due to some other exceptional circumstance. If that
    is the case then all you need to do to clean up is to shrink the temporary
    tablespace and move on in life.

    But what if you don’t know? Before you decide to shrink you may need to do some
    investigation into the causes of the large tablespace. If this happens on a
    regular basis then it is possible that your database just needs that much space.

    The dynamic performance view

    V$TEMPSEG_USAGE
    

    can be very useful in determining the cause.

    Maybe you just don’t care about the cause and you just need to shrink it.
    This is your third day on the job. The data in the database is only 200MiB
    if data and the temporary tablespace is 13GiB – Just shrink it and move on.
    If it grows again then we will look into the cause. In the mean time I am
    out of space on that disk volume and I just need the space back.

    Let’s take a look at shrinking it. It will depend a little on what version
    of Oracle you are running and how the temporary tablespace was set up.
    Oracle will do it’s best to keep you from making any horrendous mistakes
    so we will just try the commands and if they don’t work we will shrink
    in a new way.

    First let’s try to shrink the datafile. If we can do that then we get back
    the space and we can worry about why it grew tomorrow.

    SQL>
    SQL> alter database tempfile '/the/full/path/to/temp01.dbf' resize 256M; 
    alter database tempfile '/the/full/path/to/temp01.dbf' resize 256M
    *   
    ERROR at line 1:
    ORA-03297: file contains used data beyond requested RESIZE value
    

    Depending on the error message you may want to try this with different sizes
    that are smaller than the current site of the file. I have had limited
    success with this. Oracle will only shrink the file if the temporary tablespace
    is at the head of the file and if it is smaller than the size you
    specify. Some old Oracle documentation (they corrected this) said that
    you could issue the command and the error message would tell you what
    size you could shrink to. By the time I started working as a DBA this was
    not true. You just had to guess and re-run the command a bunch of times
    and see if it worked.

    Alright. That didn’t work. How about this.

    SQL> alter tablespace YOUR_TEMP_TABLESPACE_NAME shrink space keep 256M;
    

    If you are in 11g (Maybee in 10g too) this is it! If it works you may want
    to go back to the previous command and give it some more tries.

    But what if that fails. If the temporary tablespace is the default temporary
    that was set up when the database was installed then you may need to do a
    lot more work. At this point I usually re-evaluate if I really need that
    space back. After all disk space only costs $X.XX a GiB. Usually I don’t want
    to make changes like this during production hours. That means working at 2AM
    AGAIN! (Not that I really object
    to working at 2AM – it is just that… Well I like to sleep too. And my wife
    likes to have me at home at 2AM… not roaming the downtown streets at 4AM trying
    to remember where I parked my car 3 hours earlier. I have heard of that “telecommuting”
    thing. I just worry that I will get half way through and then my internet connectivity
    will fail – then I have to rush downtown to fix it all before folks show up in the
    morning to use the database.)

    Ok… Back to the serious stuff…
    If the temporary tablespace you want to shrink is your default
    temporary tablespace, you will have to first create a new temporary
    tablespace, set it as the default temporary tablespace then drop
    your old default temporary tablespace and recreate it. Afterwords
    drop the second temporary table created.

    SQL> CREATE TEMPORARY TABLESPACE temp2
    2  TEMPFILE '/the/full/path/to/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 '/the/full/path/to/temp01.dbf' SIZE 256M REUSE
    3  AUTOEXTEND ON NEXT 128M 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.
    

    Hopefully one of these things will help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can a LINQ enabled app run on a machine that only has the .NET
Can anyone tell me how I can display a status message like 12 seconds
Can you suggest some good MVC framework for perl -- one I am aware
I'm trying to shrink some databases down so that my developers can load them
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you cast a List<int> to List<string> somehow? I know I could loop through
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can you tell me what is the difference between abstraction and information hiding in
Can I get a 'when to use' for these and others? <% %> <%#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.