ORA-25152: TEMPFILE cannot be dropped at this time
Received above error when executed the below statement:
SQL> alter database tempfile '/u01/app/temp01.dbf' drop including datafiles;
CAUSE :
An attempt was made to drop a TEMPFILE being used by online users.
SOLUTION:
Step 1: Find the sessions that are using the TEMPFILE:
SQL> select a.inst_id, b.tablespace, b.segfile#, b.segblk#,
round ( ( ( b.blocks * p.VALUE ) / 1024 / 1024 ), 2 ) size_mb, a.SID, a.serial#, a.username, a.osuser,
a.program, a.status from v$session a, v$sort_usage b, v$process c, v$parameter d, where
b.segfile# = <file number of TEMPFILE SEGMENT>
and
d.name = 'db_block_size'
and
a.saddr = b.session_addr
and
a.paddr = c.addr
order by
b.tablespace, b.segfile#, b.segblk#, b.blocks;
Step 2: Kill all sessions that are using the TEMPFILE
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
-- If you have a huge list, you can write the execution syntax online, as part of the query:
SQL> set heading off
SQL> spool runme.sql
SQL> select 'alter system kill session '''||a.sid||','||a.serial#||''' immediate;'
from
v$session a,
v$sort_usage b,
v$process c,
v$parameter d
where
d.name = 'db_block_size'
and
a.saddr = b.session_addr
and
a.paddr = c.addr
and
b.tablespace='TEMP' <-- Your TEMP tablespace name here
order by
b.tablespace,
b.segfile#,
b.segblk#,
b.blocks;
SQL> spool off;
SQL> @runme.sql
Step 3: Re-attempt to drop the TEMPFILE.
SQL> alter database tempfile '/u01/app/temp01.dbf' drop including datafiles;
REFERENCE:
http://www.dba-oracle.com/t_ora_25152_tempfile_cannot_be_dropped.htm