https://blog.csdn.net/ch7543658/article/details/39271135/
1、查看操作系统endianness格式
col platform_name for a40
SELECT *
FROM V$TRANSPORTABLE_PLATFORM
ORDER BY PLATFORM_ID;
源端与目标端都查询下面语句,看一样不一样
SELECT d.PLATFORM_NAME,
ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_NAME =d.PLATFORM_NAME;
2、在source端创建测试表空间
--在target端(暂时只先创建用户)
create user target_test
identified by oracle
temporary tablespace TEMPTS1;
User created.
grant connect,resource to target_test;
这个用户还要指定默认表空间,否则后面将是users表空间
3、在source端和target端创建 backup 的目录,其实都不用创建这个,用默认的data_pump_dir就可以了
4、检查表空间自包含(就是该表空间里的数据没有和其他表空间数据有关联,如果有关联会报错)
作用:用于检查表空间集合是否是自包含的。
语法:dbms_tts.transport_set_check(ts_list in varchar2,incl_constraints in boolean default,full_closure in boolean default false);
其中ts_list指定表空间列表,如果要指定多个表空间则使用逗号隔开,incl_constraints指定是否要检查完整性约束,full_closure指定是否要进行完全或部分相关性检查。
例子:
exec sys.dbms_tts.transport_set_check('users1,users2');
select * from sys.transport_set_violations;
在查询临时表transport_set_violations时,如果返回信息,则会显示违反自包含表空间规则的原因,如果没有返回则表示表空间时自包含的。
SQL> execute dbms_tts.transport_set_check('TSET', TRUE);
PL/SQL procedure successfully completed.
--查看自包含验证结果:
SQL> select * from transport_set_violations;
no rows selected
--没有记录说明没有错
27-JUN-19 SYS@tdb> execute dbms_tts.transport_set_check('KYC_FRE', TRUE);
PL/SQL procedure successfully completed.
27-JUN-19 SYS@tdb> select * from transport_set_violations;
no rows selected
5、将表空间KYC_FRE设置成read-only
alter tablespace TSET read only;
select tablespace_name,status
from dba_tablespaces;
待将数据文件复制到target完成后,再修改为read write.
6、生成:Transportable Tablespace Set
Transportable Tablespace Set有两部分:
1)expdp 导出的表空间的metadata
2)还有就是表空间对应的数据文件
expdp dumpfile=test01.dmp directory=backup transport_tablespaces=TSET transport_full_check=y logfile=TSET.log
7、将Transportable Tablespace set 传送到Target端
1)将表空间test 对应的数据文件copy到Target 对应的ORADATA目录下。
2)将expdp 导出的表空间metadta 数据copy 到Target 端的backup 目录下
8、在Target 系统上Import 表空间的metadata(使用target_test用户,需要用到remap_schema)
impdp directory=backup dumpfile=test01.dmp transport_datafiles=/u01/app/oracle/oradata/normal/test01.dbf remap_schema=source_test:target_test logfile=test.log
9、查看并修改源表空间状态
alter tablespace TSET read write;
10、target端验证
target目标库
只需要以下5步
create user kyc_acc identified by "123456" temporary tablespace kyc_temp;
grant create session,create view,create job to resource;
grant read,write on directory data_pump_dir to resource;
grant resource to kyc_acc;
impdp system/123456 directory=data_pump_dir dumpfile=tts_expdp_acc.dmp logfile=tts_impdp_acc.log remap_tablespace=kyc_acc:kyc_acc transport_datafiles=/u01/app/oracle/oradata/PDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf
alter user kyc_acc default tablespace kyc_acc;
alter tablespace KYC_ACC read write;
下面是一些过程详情 --create tablespace kyc_acc; --drop tablespace kyc_acc including contents and datafiles; create temporary tablespace kyc_temp; create user kyc_acc identified by "123456" default tablespace kyc_acc temporary tablespace kyc_temp; create user kyc_acc identified by "123456" temporary tablespace kyc_temp; drop user kyc_acc cascade; select tablespace_name,status from dba_tablespaces; grant create session,create view,create job to resource; grant read,write on directory data_pump_dir to resource; grant resource to kyc_acc; select * from ROLE_SYS_PRIVS where ROLE like 'RES%'; select * from ROLE_TAB_PRIVS where ROLE like 'RES%'; select * from dba_sys_PRIVS where grantee like 'KYC%'; 只创建用户,不指定默认表空间,导入时remap一下,自动创建acc1表空间,数据在acc1表空间中,但是默认表空间还是users。(加这个参数的效果remap_tablespace=kyc_acc:kyc_acc1) create user kyc_acc identified by "123456" temporary tablespace kyc_temp; impdp system/123456 directory=data_pump_dir dumpfile=tts_expdp_acc.dmp logfile=tts_impdp_acc.log remap_tablespace=kyc_acc:kyc_acc1 transport_datafiles=/u01/app/oracle/oradata/PDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf 这样就可以了remap_tablespace=kyc_acc:kyc_acc,同名就可以了,要的就是这个效果 create user kyc_acc identified by "123456" temporary tablespace kyc_temp; impdp system/123456 directory=data_pump_dir dumpfile=tts_expdp_acc.dmp logfile=tts_impdp_acc.log remap_tablespace=kyc_acc:kyc_acc transport_datafiles=/u01/app/oracle/oradata/PDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf alter user kyc_acc default tablespace kyc_acc; alter tablespace KYC_ACC read write; ============================================================= source源库
只需要5步
alter tablespace KYC_ACC read only;
expdp system/123456 directory=data_pump_dir dumpfile=tts_expdp_acc.dmp logfile=tts_expdp_acc.log transport_tablespaces=KYC_ACC transport_full_check=y
scp /u01/app/oracle/admin/tdb/dpdump/tts_expdp_acc.dmp 192.168.8.151:/u01/app/oracle/admin/pdb/dpdump/
scp /u01/app/oracle/oradata/TDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf 192.168.8.151:/u01/app/oracle/oradata/PDB/datafile/
alter tablespace KYC_ACC read write;
下面是一些过程详情 alter tablespace KYC_ACC read only; select tablespace_name,status from dba_tablespaces; SELECT * FROM V$TRANSPORTABLE_PLATFORM ORDER BY PLATFORM_ID; exec sys.dbms_tts.transport_set_check('KYC_ACC'); select * from sys.transport_set_violations; execute dbms_tts.transport_set_check('KYC_ACC', TRUE); select * from sys.transport_set_violations; grant read,write on directory data_pump_dir to kyc_acc; expdp system/123456 directory=data_pump_dir dumpfile=tts_expdp_acc.dmp logfile=tts_expdp_acc.log transport_tablespaces=KYC_ACC transport_full_check=y rm -rf /u01/app/oracle/admin/tdb/dpdump/acc.* scp /u01/app/oracle/admin/tdb/dpdump/tts_expdp_acc.dmp 192.168.8.151:/u01/app/oracle/admin/pdb/dpdump/ scp /u01/app/oracle/oradata/TDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf 192.168.8.151:/u01/app/oracle/oradata/PDB/datafile/ alter tablespace KYC_ACC read write; ============================================================= 遇到的问题 问题1 ORA-39002: invalid operation ORA-39061: import mode TRANSPORTABLE conflicts with export mode SCHEMA 原因是导出时是普通的schema mode,acc.dmp文件scp错了,这个错可以避免,是大意了 这是相同的问题 create user kyc_acc identified by "123456" temporary tablespace kyc_temp; impdp system/123456 directory=data_pump_dir dumpfile=tts_expdp_acc.dmp logfile=tts_impdp_acc.log tablespace=kyc_acc transport_datafiles=/u01/app/oracle/oradata/PDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf 加这个参数是错的tablespaces=kyc_acc ORA-39002: invalid operation ORA-39061: import mode TABLESPACE conflicts with export mode TRANSPORTABLE 问题2 source只读,要等待scp完成之后再修改成读写,否则会报下面的错 http://www.itkeyword.com/doc/9256610597391385750 Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01": system/******** directory=data_pump_dir dumpfile=acc.dmp transport_datafiles=/u01/app/oracle/oradata/PDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf logfile=acc.log Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK ORA-39123: Data Pump transportable tablespace job aborted ORA-19722: datafile /u01/app/oracle/oradata/PDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf is an incorrect version 问题3 在target提前创建用户与默认表空间与临时表空间,否则报下面的错 Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01": system/******** directory=data_pump_dir dumpfile=acc.dmp transport_datafiles=/u01/app/oracle/oradata/PDB/datafile/o1_mf_kyc_acc_gfn4lb38_.dbf logfile=acc.log Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK ORA-39123: Data Pump transportable tablespace job aborted ORA-29342: user KYC_ACC does not exist in the database 查看所属表空间 select * from user_tables where table_name='ACCT_ACCOUNT'; 据目前所了解,正长情况下需要修改表的空间和表的索引的空间,如果涉及到BOLB字段的表,修改的方式又不一样了! 否则就得移动表空间,从users到kyc_acc 把原来的移动到新修改的表空间中了 select 'alter table '|| table_name ||' move tablespace kyc_acc;' from user_tables; select 'alter index '|| index_name ||' rebuild tablespace kyc_acc;' from user_indexes; 后来的就自动放在新修改的表空间中了 alter user kyc_acc default tablespace kyc_acc;