Cannot Drop Empty Datafile From Tablespace ORA-03262 (Doc ID 1353029.1)

Last updated on SEPTEMBER 20, 2016

Applies to:

Oracle Database - Enterprise Edition - Version 11.2.0.2 and later
Information in this document applies to any platform.
***Checked for relevance on 20-Sep-2016***

Symptoms

ALTER TABLESPACE ... DROP DATAFILE fails consistently with ORA-3262 'the file
is non-empty', even if there are no segments (including temporary and recycle bin) in the datafile.

TESTCASE
~~~~~~~~

drop tablespace test1_ts including contents and datafiles;

drop tablespace test2_ts including contents and datafiles;

create tablespace test1_ts
datafile '/oracle/oradata/d1v11202/test1_1_ts.dbf' size 10M autoextend on maxsize unlimited,
'/oracle/oradata/d1v11202/test1_2_ts.dbf' size 10M autoextend on maxsize unlimited;

create tablespace test2_ts
datafile '/oracle/oradata/d1v11202/test2_1_ts.dbf' size 10M autoextend on maxsize unlimited,
'/oracle/oradata/d1v11202/test2_2_ts.dbf' size 10M autoextend on maxsize unlimited;

/*
SQL> select file#, relfile#, ts# from file$;

FILE# RELFILE# TS#
---------- ---------- ----------
1 1 0
2 2 1
3 3 2
4 4 4
5 5 5
6 6 6
7 7 8
8 8 9
9 9 10
10 10 11
11 11 13

FILE# RELFILE# TS#
---------- ---------- ----------
12 12 14
13 13 14
14 14 15
15 15 15

15 rows selected.
*/

drop tablespace test1_ts including contents;

drop tablespace test2_ts including contents;

host rm /oracle/oradata/d1v11202/test1_1_ts.dbf

host rm /oracle/oradata/d1v11202/test1_2_ts.dbf

host rm /oracle/oradata/d1v11202/test2_1_ts.dbf

host rm /oracle/oradata/d1v11202/test2_2_ts.dbf

/*to duplicate the rfile# */
alter session set events '10120 trace name context forever';

create tablespace test1_ts
datafile '/oracle/oradata/d1v11202/test1_1_ts.dbf' size 10M autoextend on maxsize unlimited,
'/oracle/oradata/d1v11202/test1_2_ts.dbf' size 10M autoextend on maxsize unlimited;

conn / as sysdba

create tablespace test2_ts
datafile '/oracle/oradata/d1v11202/test2_1_ts.dbf' size 10M autoextend on maxsize unlimited,
'/oracle/oradata/d1v11202/test2_2_ts.dbf' size 10M autoextend on maxsize unlimited;

/*Next steps need to be adapted to your results*/

SQL> select file#, relfile#, ts# from file$;

FILE# RELFILE# TS#
---------- ---------- ----------
1 1 0
2 2 1
3 3 2
4 4 4
5 5 5
6 6 6
7 7 8
8 8 9
9 9 10
10 10 11
11 11 13

FILE# RELFILE# TS#
---------- ---------- ----------
12 13 14
13 14 14
14 14 15
15 15 15

15 rows selected.

/*TS# 14 and 15 each have 2 datafiles:(12, 13) and (14,15) with a common rfile# 14 for file#(13,14).
You need to see in which ts# the file with rfile# 14 (duplicate) is the first - meaning it cannot be dropped.
Drop file# 15 - drop the datafile from the tablespace where rfile# 14 is the first databafile.
Create a segment in this tablespace which has only 1 datafile left.
Try to drop after that the dtaafile from the first tablespace (where it is the second datafile), which is empty.
In this case, it would be file# 13 which has the same rfile# 14 as file#14, which is not empty.
*/

SQL> alter tablespace test2_ts drop datafile 15;

Tablespace altered.

SQL> create table test_drop tablespace test2_ts as select * from dual;

Table created.

SQL> select file#, type#, ts#, block# from seg$ where file# = 14 and type# != 3;

FILE# TYPE# TS# BLOCK#
---------- ---------- ---------- ----------
14 5 15 130

SQL> alter tablespace test1_ts drop datafile 13;
alter tablespace test1_ts drop datafile 13
*
ERROR at line 1:
ORA-03262: the file is non-empty

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms