日期:2014-05-16  浏览次数:20440 次

删除表空间出现ORA-22868错误

今天删除一个不在使用的表空间时,碰到了ORA-22868 错误。

这篇文章描述错误现象。

在测试CONVERT DATABASE 迁移命令时,没有迁移其中一个OFFLINE 的表空间,因为这个表空间中的内容已经无法恢复了。

迁移完成后,发现表空间和数据文件信息还保留在数据字典中,因此想要清除掉这些信息,而引发了这个错误。

SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
EXAMPLE
YANGTK
MGMT_TABLESPACE
TEST
MGMT_ECM_DEPOT_TS
USERS
TEMP

10 rows selected.

SQL> select name from v$datafile;

NAME
------------------------------------------
/data/oradata/ytktran/SYSTEM01.DBF
/data/oradata/ytktran/UNDOTBS01.DBF
/data/oradata/ytktran/SYSAUX01.DBF
/opt/ora10g/product/10.2.0/db_1/dbs/MISSING00004
/data/oradata/ytktran/EXAMPLE01.DBF
/data/oradata/ytktran/YANGTK01.DBF
/data/oradata/ytktran/MGMT.DBF
/data/oradata/ytktran/YANGTK02.DBF
/data/oradata/ytktran/TEST01.DBF
/data/oradata/ytktran/MGMT_ECM_DEPOT1.DBF

10 rows selected.

SQL> select file_name
2 from dba_data_files
3 where tablespace_name = 'USERS';

FILE_NAME
--------------------------------------------
/opt/ora10g/product/10.2.0/db_1/dbs/MISSING00004

显然USERS 表空间是要删除的表空间:

SQL> drop tablespace users;
drop tablespace users
*
ERROR at line 1:
ORA-01549: tablespace not empty, use INCLUDING CONTENTS option


SQL> drop tablespace users including contents;
drop tablespace users including contents
*
ERROR at line 1:
ORA-22868: table with LOBs contains segments in different tablespaces

由于表空间不为空,因此需要INCLUDING CONTENTS 方式删除表空间,但是这时出现了ORA-22868 错误。

错误信息很明确,应该是USERS 表空间中包含了LOB 表,而LOB 表中的LOB 对象存储在USERS 表空间之外的地方。

只需要找到这些对象并删除就可以解决这个问题:

SQL> col owner format a15
SQL> col tablespace_name format a15
SQL> col column_name format a30
SQL> select a.owner, a.table_name, b.column_name, b.tablespace_name
2 from dba_tables a, dba_lobs b
3 where a.owner = b.owner
4 and a.table_name = b.table_name
5 and a.tablespace_name = 'USERS'
6 and b.tablespace_name != 'USERS';

no rows selected

SQL> select a.owner, a.table_name, b.column_name, b.tablespace_name
2 from dba_tables a, dba_lobs b