Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-01652 Unable to extend temp segment by in tablespace

I am creating a table like

create table tablename as select * for table2 

I am getting the error

ORA-01652 Unable to extend temp segment by in tablespace 

When I googled I usually found ORA-01652 error showing some value like

Unable to extend temp segment by 32 in tablespace 

I am not getting any such value.I ran this query

select     fs.tablespace_name                          "Tablespace",     (df.totalspace - fs.freespace)              "Used MB",     fs.freespace                                "Free MB",     df.totalspace                               "Total MB",     round(100 * (fs.freespace / df.totalspace)) "Pct. Free"  from     (select        tablespace_name,        round(sum(bytes) / 1048576) TotalSpace     from        dba_data_files     group by        tablespace_name     ) df,     (select        tablespace_name,        round(sum(bytes) / 1048576) FreeSpace     from        dba_free_space     group by        tablespace_name     ) fs  where     df.tablespace_name = fs.tablespace_name;  

Taken from: Find out free space on tablespace

and I found that the tablespace I am using currently has around 32Gb of free space. I even tried creating table like

create table tablename tablespace tablespacename as select * from table2  

but I am getting the same error again. Can anyone give me an idea, where the problem is and how to solve it. For your information the select statement would fetch me 40,000,000 records.

like image 338
Niranjan Sonachalam Avatar asked Aug 07 '12 05:08

Niranjan Sonachalam


People also ask

How do you extend a temp segment in tablespace?

To do this, first execute “SELECT * From DBA_DATA_FILES;” in order to determine the name of the file for the tablespace. You can then extend the size by replacing the file name with the name from the aforementioned query, and entering the “ALTER TABLESPACE ADD DATAFILE” command prompt in Oracle.

How do I fix error ORA 01652?

Resolving The Problem Ask your I.T. department's Oracle DBA (administrator) to increase the size of the (full) Oracle temporary tablespace and (if necessary) free up hard drive space on the database server. Also, check to see if the Oracle database server's hard drives are full.

How do you avoid ORA 1652?

Answer: Normally, you would just add disk to TEMP to avoid the ORA-1652 error, but you can also wait for SMON to clean-up the TEMP segment.

How do I resize temp tablespace?

Temporary tablespaces: You can decrease the size of your temporary tablespace using the SHRINK command. Example: SQL> ALTER TABLESPACE example-tablespace SHRINK SPACE KEEP 100M; For resizing temporary tablespaces in a read replica, use the rdsadmin.


1 Answers

I found the solution to this. There is a temporary tablespace called TEMP which is used internally by database for operations like distinct, joins,etc. Since my query(which has 4 joins) fetches almost 50 million records the TEMP tablespace does not have that much space to occupy all data. Hence the query fails even though my tablespace has free space.So, after increasing the size of TEMP tablespace the issue was resolved. Hope this helps someone with the same issue. Thanks :)

like image 100
Niranjan Sonachalam Avatar answered Oct 06 '22 06:10

Niranjan Sonachalam