How to RESOLVE ORA-01652: unable to extend temp segment

Ora-01652
As a DBA, we often face this error ORA-01652 on a daily basis. Today, we will discuss how to resolve this. This error occurs when Oracle cannot allocate space for a temporary segment in the TEMP tablespace. Let’s discuss more in detail :

Possible Causes for ORA-01652:

1. Insufficient TEMP Tablespace Size

When there is no free space and autoextend is off.

2. Sorting or Large Queries :

Due to a complex query that needs large sorts, hash or joins

3. Parallel Queries :

Each parallel process may require its own temp space

4. Global Temporary tablespace or LOB :

Large inserts or updates to Global Temporary Tablespace or LOBs requiring TEMP space.

Solution :

1. Check Temp Usage

SELECT tablespace_name,
SUM(bytes) / 1024 / 1024 / 1024 AS total_GB,
SUM(CASE WHEN autoextensible = 'YES' THEN 1 ELSE 0 END) AS autoextensible_count
FROM dba_temp_files
GROUP BY tablespace_name;

2. Add Space to Temporary tablespace if needed

-- Add tempfile (if space allows)
ALTER TABLESPACE temp ADD TEMPFILE '/u01/oradata/test/temp02.dbf' SIZE 2G;

-- Increase existing tempfile
ALTER DATABASE TEMPFILE '/u01/oradata/test/temp01.dbf' RESIZE 4G;

-- Enable autoextend (use with caution)
ALTER DATABASE TEMPFILE '/u01/oradata/test/temp01.dbf' AUTOEXTEND ON NEXT 5G MAXSIZE UNLIMITED;

3. Check which session is causing Temp :

SELECT s.sid, s.serial#, u.username, u.tablespace, u.contents, u.segtype,
u.blocks*8/1024 AS mb_used
FROM v$session s
JOIN v$sort_usage u ON s.saddr = u.session_addr
ORDER BY mb_used DESC;

4. Check the Query Plans

Check execution plan of the query which is taking much space in the Temp Tablespace. If it’s going for Full Table Sacn, check any index is required. Else check with Application Team if required.

Hope this helps to resolve ORA-01652 error. Also, you can get more information about this from the Oracle Doc as well.

Other ORA error related Articles :

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top