如何删除offline数据文件/表空间上的分区

接上一篇“Oracle 10g RAC全库flashback

http://www.cnblogs.com/cqubityj/p/3265552.html

在打开数据库之前把2013-05-17号的数据文件offline了,这个表空间存储的是2013-05-17号的分区数据。这造成对某些分区表的全表查询出错 (类似select  * from <partitioned_table_name>这样的语句) ,即使这个表是空的也会出错。因为Oracle不去扫描表是不可能知道表里有没有数据的,但因为数据文件或表空间已经offline了,扫描表时必然会报错。

报错类似:

SQL> select * from cut.CUT_SP_OPERATOR;
select * from cut.CUT_SP_OPERATOR
                  *
ERROR at line 1:
ORA-00376: file 90 cannot be read at this time
ORA-01110: data file 90: '/oracle/data2/BEICENP/CUT_MAY172013_DATA.dbf'

对于这个问题,可以通过exchange partition的方式来解决。由于exchange partition只是更改数据字典信息,而不会去扫描表和分区,因此操作不会报错,能正常执行。

具体步骤如下:

1、检查表空间上存储了哪些表分区

select owner,segment_name, partition_name,segment_type
from dba_segments
where segment_type='TABLE PARTITION' and
tablespace_name in ('CUT_MAY172013_DATA')
order by segment_name;

如果有table subpartition的话,也要做检查

2、对步骤1查出的每个表分区做exchange partition

删除临时表

drop table cut.temp purge;

创建与分区表结构一致的临时表
create table cut.TEMP tablespace cut_data as select * from cut.CUT_SP_FINANCIAL where 1=2;

交换表和分区
alter table cut.CUT_SP_FINANCIAL exchange partition MAY172013 with table cut.TEMP;

3、删除分区

在exchange partition完成后,可以删除表分区。分区删除后,select 语句就不会再报错了。

原文地址:https://www.cnblogs.com/cqubityj/p/3272182.html