思想:将LE01数据库中tsport表空间迁移到LE02数据库中;
清理环境
drop user tsport cascade;
drop tablespace tsport including contents and datafiles;
1、初始化实验环境
sqlplus sys/oracle@LE01 as sysdba
create tablespace tsport datafile '/u01/app/oracle/oradata/LEO1/tsport01.dbf' size 20m autoextend off;
create user tsport identified by tsport default tablespace tsport;
grant connect,resource to tsport;
conn tsport/tsport
create table t1 (a int) tablespace tsport;
insert into t1 values (100);
commit;
create index idx_t1 on t1 (a) tablespace tsport;
select index_name,table_name,tablespace_name from user_indexes where table_name='T1';
conn / as sysdba
select tablespace_name,segment_name,segment_type from dba_segments where tablespace_name='TSPORT'; 查看TSPORT表空间有哪些对象
2、检查TSPORT表空间是否违反约束条件
exec dbms_tts.transport_set_check('TSPORT',true);
例如表在A表空间,索引在B表空间,如果只传输A的话,就会违反自包含约束条件,表上的索引就会失效,传输不完整,解决方法:同时传输A和B两个表空间。
select * from transport_set_violations; 查看违反约束列表,没有记录为正常
3.设置TSPORT为只读表空间,即把所有数据文件都设置成只读状态。
alter tablespace tsport read only;
4、使用expdp导出表空间的元数据
create directory dir_tmp as '/home/oracle';
grant read,write on directory dir_tmp to public;
expdp system/oracle dumpfile=tsport.dmp directory=dir_tmp transport_tablespaces=tsport
使用SYSTEM用户只导出tsport表空间的元数据(结构信息),而不是真实数据,因此容量比较小
5、拷贝刚导出的元数据文件和数据文件(表空间真正的数据)只有数据文件为只读状态才可以复制,而且不用停库
(1)元数据文件传输到第二台机器上
[oracle@leonarding1 ~]$
scp tsport.dmp oracle@192.168.1.101:/home/oracle
oracle@192.168.1.101's password:
tsport.dmp 100% 76KB 76.0KB/s 00:00
(2)数据文件(表空间真正的数据) 传输到第二台机器上
[oracle@leonarding1 LEO1]$
scp tsport01.dbf oracle@192.168.1.101:/u01/app/oracle/oradata/LE02
oracle@192.168.1.101's password:
tsport01.dbf 100% 20MB 20.0MB/s 00:01
6、 impdp的传输表空间导入
LE02库的准备工作
create user tsport identified by tsport;
grant connect,resource to tsport;
create directory dir_tmp as '/home/oracle';
grant read,write on directory dir_tmp to public;
impdp system/oracle directory=dir_tmp dumpfile= tsport.dmp remap_schema=tsport:tsport transport_datafiles=/u01/app/oracle/oradata/LE02/tsport01.dbf
7、检查表空间是否导入成功
col tablespace_name for a15
col segment_name for a15
col segment_type for a15
select tablespace_name,segment_name,segment_type from dba_segments where tablespace_name='TSPORT';
conn tsport/tsport
select * from t1;
7.将LE01实例和LE02实例表空间调整为可读写状态
sqlplus sys/oracle@LE02 as sysdba
conn / as sysdba
select tablespace_name,status from dba_tablespaces;
alter tablespace tsport read write;
select tablespace_name,status from dba_tablespaces;
sqlplus sys/oracle@LE01 as sysdba
conn / as sysdba
select tablespace_name,status from dba_tablespaces;
alter tablespace tsport read write;
select tablespace_name,status from dba_tablespaces;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29330852/viewspace-1078326/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29330852/viewspace-1078326/