ORA-1652: unable to extend temp segment by 128 in tablespace TEMP

This post covers quick fix for temp tablespace issue (ORA-1652) which is to add temporary datafile and then find root cause of temp tablespace issue.

Extent – An extent is a logical unit of database storage space allocation made up of a number of contiguous data blocks. One or more extents make up segment.

Segment – A segment is a set of extents that contains all the data for a specific logical storage structure within a tablespace. To know more click here

Temporary Tablespace – contains transient data that persists only for the duration of the session. To know more  click here

.
Quick Fix for ORA-1652

1. Identify temporary datafile details :
SQL> select file_name , TABLESPACE_NAME from DBA_TEMP_FILES;
—–
/u01/oradata/VIS11i/temp01.dbf   TEMP

2. Check if there is any space available in temporary tablespace (segment)

SQL> SELECT   A.tablespace_name tablespace, D.mb_total,
SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total – SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM     v$sort_segment A,
(
SELECT   B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
FROM     v$tablespace B, v$tempfile C
WHERE    B.ts#= C.ts#
GROUP BY B.name, C.block_size
) D
WHERE    A.tablespace_name = D.name
GROUP by A.tablespace_name, D.mb_total;


—-
output like

TABLESPACE                        MB_TOTAL    MB_USED    MB_FREE
——————————- ———- ———- ———-
TEMP                                  2548         2536       12

(in above case out of 2 GB only 12 MB is free)

.

3.  Temporary fix

a) Resize temporary file as
SQL> ALTER DATABASE TEMPFILE ‘/u01/oradata/VIS11i/temp01.dbf’ RESIZE 3072M;

or

b) Add temp datafile to temporary tablespace as

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE ‘/u01/oradata/VIS11i/temp02.dbf’
SIZE 1024M REUSE AUTOEXTEND ON NEXT 50M  MAXSIZE 1024M;

.

Root Cause Analysis

1.  Identify temp segment usages per session


— Temp segment usage per session.

SQL> SELECT   S.sid || ‘,’ || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,
P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) statements
FROM     v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE    T.session_addr = S.saddr
AND      S.paddr = P.addr
AND      T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY mb_used;

2. Identify temp segment usages per statement

— Temp segment usage per statement.

SQL> SELECT  S.sid || ‘,’ || S.serial# sid_serial, S.username, Q.hash_value, Q.sql_text,
T.blocks * TBS.block_size / 1024 / 1024 mb_used, T.tablespace
FROM    v$sort_usage T, v$session S, v$sqlarea Q, dba_tablespaces TBS
WHERE   T.session_addr = S.saddr
AND     T.sqladdr = Q.address
AND     T.tablespace = TBS.tablespace_name
ORDER BY mb_used;

Depending on outcome of temp segment usage per session and per statement focus on problematic session/statement.

.
References/Related

Did you get a chance to download Free Interview Questions related to Database? If not, download it here http://k21academy.com/oracle-dba-12c-interview-question

Database interview questions

About the Author Atul Kumar

Oracle ACE, Author, Speaker and Founder of K21 Technologies & K21 Academy : Specialising in Design, Implement, and Trainings.

follow me on:

Leave a Comment:

4 comments
dhoulath says July 28, 2009

Hi,
we had a issue in our production server.
there were plenty of free space in temp tablespace around 20 GB but when we checked temp headers it showed us 100% full.
What might have caused this issue?
Also adding space is not a advisable solution in PRODUCTION database environments..is it possible to coalesce temp segments online or make sessions release unused temp segments?

Reply
prabhu says August 14, 2009

even though tablespace has be created with autoextent feature why it cant increase its size automatically?this error occurs not only with temp also with other tabllespaces.

Reply
Raviteja says May 22, 2017

Hi my default temorary tablespace is TEMP but I am getting above error for TEMP2.

Reply
Rosel says December 21, 2018

Thanks for sharing. It will help me to troubleshoot TEMPORARY Tablespace issues.

Reply
Add Your Reply

Not found