alter table move tablespace move表的表空间

--最近发现生产上,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;


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值