Move Tablespace for Partition Tables

客户有一需求,要将一个 tablespace 上所有的 objects 移到另外一个 tablespace 上,过程记录如下:

1,检查该TBS上存在哪些类型的Segment
select distinct segment_type
  from dba_segments
where owner = 'USER_NAME'
   and tablespace_name = 'TBS_NAME';

发现有五种,分别是 TABLE, INDEX, TABLE PARTITION, TABLE SUBPARTITION, INDEX PARTITION, INDEX SUBPARTITION,接下来针对不同类型的 Segment 进行不同的操作,至于如何把实际需要运行的SQL兜出来,就不做详细解释了。

2,针对 Table 执行如下命令
alter table USER_NAME.TABLE_NAME move tablespace NEW_TBS_NAME;


3,针对 Index 执行如下命令
alter index USER_NAME.INDEX_NAME rebuild tablespace NEW_TBS_NAME;


4,针对含 Partition Table 执行如下命令
alter table USER_NAME.TABLE_NAME move partition PARTITION_NAME tablespace NEW_TBS_NAME;
alter table USER_NAME.TABLE_NAME modify default attributes tablespace NEW_TBS_NAME;


5,针对含 SubPartition Table 执行如下命令
alter table USER_NAME.TABLE_NAME move subpartition SUBPARTITION_NAME tablespace NEW_TBS_NAME;
alter table USER_NAME.TABLE_NAME modify default attributes tablespace TABLE_NAME;
alter table USER_NAME.TABLE_NAME modify default attributes for partition PARTITION_NAME tablespace NEW_TBS_NAME;


6,针对含 Partition Index 执行如下命令
alter index USER_NAME.INDEX_NAME rebuild partition PARTITION_NAME tablespace NEW_TBS_NAME;


7,针对含 SubPartition Index 执行如下命令
alter index USER_NAME.INDEX_NAME rebuild subpartition SUBPARTITION_NAME tablespace NEW_TBS_NAME;

这里要特别注意的是,在包含 Partition 或者 SubPartition 的 Table 中,除了需要将数据全部转移到新的 Tablespace 之外,还需要将上一层 Table 或者 Partition 的定义属性中的 Tablespace 信息也修改成新的 Tablespace,具体请参考蓝色标记的SQL语句,这样才完美。

最后需要检查所有相关的 Index 是否可用,最好是通过以下命令再确认一下各个 Segment 的定义中是否还存在旧的 Tablespace 信息
select dbms_metadata.get_ddl('TABLE','TABLE_NAME','USER_NAME') from dual;
select dbms_metadata.get_ddl('INDEX','INDEX_NAME','USER_NAME') from dual;


[本日志由 Sonic 于 2010-01-21 00:42 AM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 4 | 引用: 0 | 查看次数: -
回复回复candy[2010-01-22 12:45 AM | del]
看不懂,不知所云
回复回复晓鑫[2010-01-21 09:43 AM | del]
真是勤劳的小蜜蜂啊!!
回复回复Sonic[2010-01-21 09:41 AM | del]
有ICP备案就没问题的,看我博客最下面的几行小字
回复回复Nimo妈[2010-01-21 09:24 AM | del]
听说政府规定个人博客不准使用了啊,好多个人名义开立的博客域名都被关闭了
你这个是属于个人博客麽?
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.