建立含有lob字段的表时,oracle会自动为lob字段建立两个单独的segment,一个用来存放lob数据,另一个用来存放lob索引,并且它们都会存储在对应表指定的表空间中。但是当我们用alter table tb_name move tablespace tbs_name;对表做表空间之间迁移时只能迁移非lob字段以外的segment,而如果要在移动表数据同时移动lob相关字段,就必需用如下的含有特殊参数据的文句来完成:
alter table tb_name move tablespace tbs_name lob (column_lob1,column_lob2) store as(tablespace tbs_name);
表包含lob字段,需要收回空间,首先move表,move表,move完表后lob的空间并不会释放,还需要针对lob字段进行move。
非分区表lob的move:
alter table T_SEND_LOG move lob(MESSAGE) store as (tablespace DATALOB);
分区表lob的move:
alter table T_SEND_LOG move partition p2018 lob(MESSAGE) store as (tablespace DATALOB);
分区表move:
alter table T_SEND_LOG move partition p2018;
注意:move表后记得rebuild索引。
批量生成语句参考:
针对表空间:
select 'alter table ' || a.owner || '.' || a.table_name || ' move lob(' ||
a.COLUMN_NAME || ') store as (tablespace DATALOB);'
from dba_lobs a, DBA_SEGMENTS b
where a.owner in ('APP')
and a.OWNER = b.OWNER
and a.SEGMENT_NAME = b.SEGMENT_NAME
and b.TABLESPACE_NAME != 'PACSLOB';
针对表:
select 'alter table ' || a.owner || '.' || a.table_name || ' move lob(' ||
a.COLUMN_NAME || ') store as (tablespace DATALOB);'
from dba_lobs a, DBA_SEGMENTS b
where a.owner in ('APP')
and a.OWNER = b.OWNER
and a.SEGMENT_NAME = b.SEGMENT_NAME
and a.TABLE_NAME = 'T_SEND_LOG';
======================= =======================
ORA-14511: cannot perform operation on a partitioned object
解决:如下的sql就可以生成成百上千条语句来完成partition级别的move操作
select 'alter table ' || table_name || ' move partition ' || partition_name ||' tablespace users;'
from dba_tab_partitions
where table_name in('&table_name') and table_owner='&table_owner';
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2638118/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31397003/viewspace-2638118/