ORA-01652: Unable to Extend Temp Segment in Temporary Tablespace is one of the most frequently encountered Oracle space errors, especially during heavy data loads, reporting queries, or sorts.
This error means Oracle ran out of temporary space to perform operations like sorting, joining, or creating indexes.
It’s not a corruption or structural issue — it’s a space management problem in the TEMP tablespace.
Let’s understand what causes this error, how to fix it fast, and how to prevent it permanently.
What Does ORA-01652 Mean?
You’ll see something like this in your logs or application output:
ORA-01652: unable to extend temp segment by 128 in tablespace TEMP
This indicates that Oracle tried to allocate temporary space for a sort or hash operation — but there was no free space available in the TEMP tablespace.
Why the Error Happens
Here are the most common reasons behind ORA-01652:
- TEMP tablespace is full — no free space left.
- Sort or hash join exceeded available TEMP size.
- Autoextend not enabled on TEMP datafiles.
- Runaway queries or reports consuming large temp space.
- Multiple sessions performing large sorts simultaneously.
- Old temporary segments not cleaned up due to abnormal session termination.
Step-by-Step Troubleshooting Guide
Step 1: Check TEMP Tablespace Usage
Run this query:
SELECT tablespace_name,
SUM(bytes_used)/1024/1024 AS used_mb,
SUM(bytes_free)/1024/1024 AS free_mb
FROM v$temp_space_header
GROUP BY tablespace_name;
If free_mb is very low, the TEMP tablespace is almost full.
You can also monitor session-level temp usage:
SELECT username, tablespace, segtype, SUM(blocks)*8/1024 AS mb_used
FROM v$sort_usage
GROUP BY username, tablespace, segtype;
Step 2: Identify Top TEMP Consumers
Run:
SELECT s.sid, s.serial#, s.username, u.tablespace, u.segtype,
ROUND((u.blocks*8)/1024,2) AS temp_mb, s.program
FROM v$sort_usage u, v$session s
WHERE u.session_addr = s.saddr
ORDER BY temp_mb DESC;
This shows which sessions or queries are consuming the most TEMP space.
If you spot a runaway session, you can terminate it:
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
Step 3: Check TEMP Datafile Configuration
SELECT file_id, file_name, bytes/1024/1024 AS size_mb, autoextensible
FROM dba_temp_files;
If autoextensible = NO, Oracle won’t expand the TEMP file automatically.
✅ Fix:
ALTER DATABASE TEMPFILE '/u01/oradata/ORCL/temp01.dbf' AUTOEXTEND ON NEXT 500M MAXSIZE UNLIMITED;
Step 4: Add a New TEMP File (If Space Permits)
ALTER DATABASE ADD TEMPFILE '/u02/oradata/ORCL/temp02.dbf' SIZE 5G AUTOEXTEND ON NEXT 500M;
This allows Oracle to distribute sort operations across multiple files.
💡 Tip: Always place TEMP files on fast disks — ideally SSD or NVMe.
Step 5: Shrink or Recreate TEMP Tablespace
If TEMP is too fragmented or bloated:
Option 1 – Shrink TEMP:
ALTER DATABASE TEMPFILE '/u01/oradata/ORCL/temp01.dbf' RESIZE 4G;
Option 2 – Recreate TEMP Tablespace:
CREATE TEMPORARY TABLESPACE TEMP2 TEMPFILE '/u02/oradata/ORCL/temp02.dbf' SIZE 10G AUTOEXTEND ON;
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP2;
DROP TABLESPACE TEMP INCLUDING CONTENTS AND DATAFILES;
Step 6: Tune Problematic SQL
Sometimes the issue isn’t storage — it’s a bad query design.
Check the SQL using TEMP:
SELECT sql_id, sql_text
FROM v$sql_workarea_active
WHERE operation_type IN ('SORT','HASH-JOIN','BITMAP MERGE');
Then tune it:
- Add proper indexes.
- Avoid sorting large datasets unnecessarily.
- Use
PARALLELonly when needed.
Real-World Example
A financial analytics database threw hundreds of ORA-01652 errors during monthly report generation.
TEMP tablespace was 10GB — completely full.
DBA Actions:
- Identified large queries via
v$sort_usage. - Added an extra TEMP file (10GB).
- Enabled autoextend.
- Tuned two major SQL queries performing massive sorts.
✅ Result: Report generation time dropped from 45 minutes to 8 minutes, and no further TEMP errors occurred.
Best Practices to Prevent ORA-01652
- Size TEMP tablespace correctly — 1.5x to 2x your largest sort operation.
- Enable AUTOEXTEND on TEMP datafiles.
- Monitor TEMP usage using AWR or custom alerts.
- Kill abandoned sessions that consume TEMP space.
- Use multiple TEMP files for parallel workloads.
- Regularly validate TEMP with
SELECT * FROM v$temp_space_header;
Related Articles
- Fixing the “Error in invoking target ‘agent nmhs’ of makefile ins_emagent.mk” During Oracle 11.2.0.4 Installation on Linux
- ORA-04031: Unable to Allocate Shared Memory – Causes, Fixes, and Prevention (Oracle DBA Guide)
- Oracle Database 19c Upgrade Using AutoUpgrade Tool: Step-by-Step Guide for 11gR2, 12cR2, and 18c (Non-CDB)
Final Thoughts
The ORA-01652: Unable to Extend Temp Segment in Temporary Tablespace error is often more about resource planning than troubleshooting.
A well-sized TEMP tablespace and tuned SQL workload can eliminate this error for good.
The best DBAs don’t just react to space issues — they design their databases to prevent them.



