56.如何删除Oracle表空间数据文件

1.找到要删除对象

举例:
--test表空间10号数据文件删除。

(1)表分区移动。
select distinct 'alter table '||owner||'.'||segment_name||' move partition '||partition_name||' tablespace '||'TEST2'
from dba_extents
where tablespace_name='TEST'  
and segment_type ='TABLE PARTITION'
and file_id=10 ;
(2)索引分区移动
select distinct 'alter index '||owner||'.'||segment_name||' rebuild partition '||partition_name||' online tablespace  TEST2'
from dba_extents
where tablespace_name='TEST' 
and segment_type ='INDEX PARTITION'
and file_id=10 ;
(3)普通表移动
select distinct 'alter table '||owner||'.'||segment_name||' move tablespace  TEST2'
from dba_extents
where tablespace_name='TEST' 
and segment_type ='TABLE'
and file_id=10 ;
(4)重建普通索引到表空间test2;
select distinct 'alter index '||owner||'.'||segment_name||' rebuild online tablespace '||v_tbs_tmp
from dba_extents
where tablespace_name='TEST'
and segment_type ='INDEX'
and file_id=10 ;

注意:
除了表,索引以外,还要检查其他的数据库对象是否在当前文件中,如果在也要移动走。

2.生成移动表分区,索引分区,普通表,普通索引的语句 

alter table test.test1 move partition test_p1 tablespace test2;
alter index test.idx_p_test1 rebuild partition idx_p1 online tablespace test2;
alter table test.test2  move tablespace  test2;
alter index test.Idx_test2 rebuild online tablespace  test2;

3.删除表壳空间的数据文件10。

alter tablespace test drop datafile 10;

4.重新移动回原来的表空间

alter table test.test1 move partition test_p1 tablespace test;
alter index test.idx_p_test1 rebuild partition idx_p1 online tablespace test;
alter table test.test2 move tablespace test;
alter index test.Idx_test2 rebuild online tablespace test;

5.总结 

删除数据文件的表空间的基本思路就是将要删除的数据文件中的对象先临时移动到别的表空间。

删除要删除的数据文件,然后将移动出去的数据库对象重新移动回来。需要注意,如果有其他的对象也要移动到别的表空间,然后再移动回来。不能漏掉对象。导致数据库不完整。

  • 8
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值