一、移动分区表的表空间
-
非组合分区表
alter table gaodc.T_GNLK_ZSXX move PARTITION PART_RZSJ_001 tablespace BKJ_GAODC_KK_DATA1; -
组合分区表:
(1)先移动子分区到另一个表空间 :
alter table RPT_F_CABECF move SUBPARTITION SYS_SUBP8842 tablespace BKJ_GAODC_KK_DATA1;(2)subpartition已经move走了,就剩下subpartition的father了,那就不需要move了,改一下分区的属性就可以了。
ALTER TABLE RPT_F_CABECF MODIFY DEFAULT ATTRIBUTES FOR PARTITION PARTITION_660 TABLESPACE BKJ_GAODC_KK_DATA1;注:
如直接move含有子分区的分区将发生如下错误
ORA-14257: cannot move partition other than a Range or Hash partition
二、移动分区表上index的表空间
1)非分区index
ALTER index GAODC.PK_T_GNLK_ZSXX_XXZJBH rebuild tablespace BKJ_GAODC_KK_DATA1;
2)无子分区的index
ALTER INDEX IDX_RPT_F_STATION_DP_1 REBUILD PARTITION SYS_P3721 TABLESPACE BKJ_GAODC_KK_DATA1;
3)子分区index
ALTER INDEX IDX_RPT_F_CABECF_1 REBUILD SUBPARTITION SYS_SUBP8842 TABLESPACE BKJ_GAODC_KK_DATA1;
三、自动生成需要的脚本
SELECT ‘alter table ’
|| table_name
|| ’ move PARTITION ’
|| partition_name
|| ’ tablespace BKJ_GAODC_KK_DATA1;’
FROM USER_TAB_PARTITIONS
WHERE SUBPARTITION_COUNT = 0 AND tablespace_name = ‘BKJ_GAODC_KK_DATA’; – 非组合分区表
SELECT ‘alter table ’
|| table_name
|| ’ move subPARTITION ’
|| SUBPARTITION_NAME
|| ’ tablespace BKJ_GAODC_KK_DATA1;’
FROM USER_TAB_SUBPARTITIONS
WHERE SUBPARTITION_COUNT > 0 AND tablespace_name = ‘BKJ_GAODC_KK_DATA’; --移动子分区
SELECT ‘ALTER TABLE ’
|| table_name
|| ’ MODIFY DEFAULT ATTRIBUTES FOR PARTITION ’
|| partition_name
|| ’ TABLESPACE BKJ_GAODC_KK_DATA1;’
FROM USER_TAB_PARTITIONS
WHERE SUBPARTITION_COUNT > 0 AND tablespace_name = ‘BKJ_GAODC_KK_DATA’;–修改母分区属性
SELECT ‘ALTER INDEX ’ || INDEX_NAME || ’ REBUILD TABLESPACE BKJ_GAODC_KK_DATA1;’
FROM USER_INDEXES
WHERE tablespace_name=‘BKJ_GAODC_KK_DATA’;
SELECT 'ALTER INDEX ’
|| index_name
|| ’ REBUILD PARTITION ’
|| PARTITION_NAME
|| ’ TABLESPACE BKJ_GAODC_KK_DATA; ’
FROM USER_IND_PARTITIONS
where SUBPARTITION_COUNT = 0
and tablespace_name=‘BKJ_GAODC_KK_DATA’; – 无子分区的index
SELECT 'ALTER INDEX ’
|| index_name
|| ’ REBUILD SUBPARTITION ’
|| SUBPARTITION_NAME
|| ’ TABLESPACE BKJ_GAODC_KK_DATA; ’
FROM USER_IND_SUBPARTITIONS
where tablespace_name=‘BKJ_GAODC_KK_DATA’; --子分区index