修改表空間 查詢owner下 對於表級別的表空間分類 select tablespace_name,count(*) from dba_tables where owner = 'OPERATION_DEVELOP_CNEMC' group by tablespace_name order by 2; 核對上面的數量情況 select * from dba_tables where owner = 'OPERATION_DEVELOP_CNEMC' and tablespace_name = 'USERS'; 查看每張表的基本信息 select table_name,num_rows from dba_tables where owner = 'OPERATION_DEVELOP_CNEMC' and tablespace_name = 'USERS' order by 2 desc; 查詢需要move表的詳細信息 select t.table_name as "表名", t.num_rows as "表行數", nvl(s.partition_name, 0) as "分區名", s.segment_type "段類型", s.bytes / 1024 / 1024 as "段大小(MB)" FROM dba_tables t, dba_segments s where t.table_name = s.segment_name(+) and t.owner = 'OPERATION_DEVELOP_CNEMC' and t.tablespace_name = 'USERS' order by s.bytes desc; select count(*) from( select table_name from dba_tables where owner = 'OPERATION_DEVELOP_CNEMC' and table_name not like 'T\_%' escape '\' and table_name not like 'JF\_%' escape '\' and table_name not like 'PAYMENT\_%' escape '\' and table_name not like 'PROM%' and table_name <> 'CUSTOMER_BUY_HIS'); 查詢需要move表的索引情況,11g中要考慮move后的索引重建,12c版本中可以支持online move select index_name,index_type,table_name,table_owner,table_type,uniqueness,status from dba_indexes where owner = 'OPERATION_DEVELOP_CNEMC' and tablespace_name = 'USERS'; 拼接move的sql語句 SELECT 'alter table '||TABLE_NAME||' move tablespace CNEMC;' FROM DBA_TABLES WHERE TABLESPACE_NAME = 'USERS' and OWNER = 'OPERATION_DEVELOP_CNEMC' order by TABLE_NAME; 拼接重建索引的sql語句(rebuild 跟 rebuid online的區分要注意,online不會阻塞dml語句) select 'alter index ' ||index_name||' rebuild online tablespace CNEMC;' from dba_indexes where table_owner = 'OPERATION_DEVELOP_CNEMC' order by index_name and status <> 'VALID'; 1、要考慮move后的索引重建問題 2、盡量放在業務低峰期或者夜間進行 3、對於大表考慮重建索引時占用的cpu跟臨時表空間的問題