首页 > 数据库 > Oracle > Oracle中表空间、表、索引的迁移
在Oracle数据库运行过程中,由于磁盘存储限制或者前期规划不充分,后期需要对表空间数据文件进行物理迁移或者数据库表及索引进行逻辑存储迁移,此次记录一下相关迁移方法。
1.将修改的表空间进行offline:
alter tablespace users offline;
2,将表空间拷贝到要存放的位置:
cp /u01/app/oracle/oradata/ORCL/user01.dbf /data/app/oracle/oradata/ORCL/user01.dbf
3,进入数据库中修改表空间的存储路径:
alter tablespace users rename datafile '/u01/app/oracle/oradata/ORCL/user01.dbf' to '/data/app/oracle/oradata/ORCL/user01.dbf';
(原来的路径修改为现在的存放路径)
4,将表空间进行online;
alter tablespace users online;
将emp表从users表空间移动到tmp表空间中去:
alter table emp move tablespace tmp;
(emp表的数据和表结构会一起移动到tmp表空间下)
将表空间users中的所有表移动到tmp表空间下:
select 'table name '||table_name||' move tablespace tmp;' from user_tables where tablespace_name='USERS';
输出的结果为脚本形式,批量执行即可。
PS: 表移动后,所有涉及的索引会失效,需要将索引进行重建。
将索引ind_emp移动到索引表空间tmp_ind中:
alter index ind_emp rebuild tablespace tmp_ind;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30484956/viewspace-2675391/ ,如需转载,请注明出处,否则将追究法律责任。