--最近发现生产上,bsales下的部分表在users表空间下。 
  
 
  
   --所以需要进行表空间转移,对于具体的步骤先在本地进行一下测试 
  
 
  
   --主要方法: 
  
 
  
   1、对于需要转移的表 
  
 
  
   alter table move tablespace ; 
  
 
  
   2、对于表中的索引 
  
 
  
   alter index tablespace rebuild online; 
  
 
  
   --实验环境:本地linux虚拟机,oracle 11gR2 
  
 
  
   --具体步骤: 
  
 
  
   1、创建测试表: 
  
 
  
   create table scott.change_tbs as select * fromdba_tables; 
  
 
  
   create table scott.change_tbs_2 as select * fromdba_objects; 
  
 
  
   2、创建主键: 
  
 
  
   alter table scott.change_tbs add constraint PK_1 primary key(owner,table_name); 
  
 
  
   alter table scott.change_tbs_2 add constraint PK_2 primary key(object_id); 
  
 
  
   3、创建索引: 
  
 
  
   create index scott.IDX_NUM_rows on scott.change_tbs(num_rows); 
  
 
  
   create index scott.IDX_object_type on scott.change_tbs_2(object_name); 
  
 
  
   4、移动表空间 
  
 
  
   alter table scott.change_tbs move tablespace roy; 
  
 
  
   alter table scott.change_tbs_2 move tablespace roy; 
  
 
  
   5、重建索引: 
  
 
  
   alter index scott.PK_1 rebuild online tablespace roy; 
  
 
  
   alter index scott.IDX_NUM_rows rebuild online tablespaceroy; 
  
 
  
   alter index scott.PK_2 rebuild online tablespace roy; 
  
 
  
   alter index scott.IDX_object_type rebuild online tablespaceroy; 
  
 
  
   --结果: 
  
 
  
   select * from dba_segments where owner='SCOTT'; 
  
 
  
   --表以及索引都移动到表空间roy 
  
 
  
   SCOTT CHANGE_TBS TABLE ASSM ROY 
  
 
  
   SCOTT CHANGE_TBS_2 TABLE ASSM ROY 
  
 
  
   SCOTT PK_1 INDEX ASSM ROY 
  
 
  
   SCOTT IDX_NUM_ROWS INDEX ASSM ROY 
  
 
  
   SCOTT PK_2 INDEX ASSM ROY 
  
 
  
   SCOTT IDX_OBJECT_TYPE INDEX ASSM ROY 
  
 
  
   select * from dba_indexes where owner='SCOTT'; 
  
 
  
   --索引状态均是valid 
  
 
  
   SCOTT IDX_NUM_ROWS   
      
     
      
    VALID 
      
 
  
   SCOTT PK_2   
      
     
      
      
     
      
      
   VALID 
          
 
  
   SCOTT PK_1   
      
     
      
      
     
      
      
   VALID 
          
 
  
   SCOTT IDX_OBJECT_TYPE   
      
     
   VALID 
     
 
  
   --但此时如果查询dba_tables会发现,这两张表的last_analyzed是空的,而索引经过重建后,last_analyzed字段已经更新 
  
 
  
   --需要重新收集一下表的信息 
  
 
  
   analyze table scott.change_tbs compute statistics; 
  
 
  
   analyze table scott.change_tbs_2 compute statistics;