1、迁移环境sql
源库:AIX-Based Systems (64-bit),11.1.0.7.0 rac
目标库:Linux x86 64-bit ,12.1.0.2 rac oracle
2、导入元数据报错ide
cat imp_xttplugin_201803.par
测试
userid='/ as sysdba' DIRECTORY=TTSIMP DUMPFILE=exp_xttplugin_201803_%u.dmp LOGFILE=imp_xttplugin_201803.log transport_datafiles=’xxx’,’xxx’,’xxx’,’xxx’....’xxx’ #共326个数据文件,篇幅问题就不cat出来了
1、执行元数据导入:
nohup impdp parfile=imp_xttplugin_201803.par > imp_xttplugin_201803.par.out &
spa
Master table "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_TRANSPORTABLE_01": /******** AS SYSDBA parfile=imp_xttplugin_201803.par Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK ORA-39123: Data Pump transportable tablespace job aborted ORA-00059: maximum number of DB_FILES exceeded Job "SYS"."SYS_IMPORT_TRANSPORTABLE_01" stopped due to fatal error at Fri Apr 27 00:24:15 2018 elapsed 0 00:05:06
这里是因为目前如今导入的库是个中间库,用户转换而已,后续是转换成pdb,因此只是很简单的建库,并无修改一下初始化参数,因此致使了报错(属于低级错误,自我检讨中)。
2、修改db_files以后,再次执行导入:
nohup impdp parfile=imp_xttplugin_201803.par > imp_xttplugin_201803.par.out &
rest
Master table "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_TRANSPORTABLE_01": /******** AS SYSDBA parfile=imp_xttplugin_201803.par Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK ORA-39123: Data Pump transportable tablespace job aborted ORA-29349: tablespace 'XXX_DATA' already exists Job "SYS"."SYS_IMPORT_TRANSPORTABLE_01" stopped due to fatal error at Fri Apr 27 00:35:29 2018 elapsed 0 00:04:37
3、查询已经导入的元数据server
--发现已经导入56个数据文件 select count(1) from dba_data_files where tablespace_name not in ('SYSTEM','USERS','SYSAUX','UNDOTBS1'); count(1) --------- 56 --发现已经导入了12个表空间,总共16个表空间 select count(1) from dba_tablespaces where tablespace_name not in ('SYSTEM','USERS','SYSAUX','UNDOTBS1'); count(1) --------- 12 --也就是说在第一次由于db_files报错的时候,在 导入TRANSPORTABLE_EXPORT/PLUGTS_BLK步骤,已经有部分元数据导入了,再次发起导入已经存在的就会存在冲突。
3、寻找解决办法htm
1、ORA-29349报错解析对象
oerr ora 29349 29349, 00000, "tablespace '%s' already exists" // *Cause: Tried to plug-in a tablespace which already exists. // *Action: Drop the offending tablespace if possible. Otherwise use a different method (e.g., import/export) to move data.
2、删除表空间的坑blog
咱们平常经常使用的删除表空间的语句有以下3种:
--删除表空间,保留表空间包含内容和物理数据文件: drop tablespace xxx; --删除表空间及包含的内容,保留物理数据文件: drop tablespace xxx including contents; --删除表空间及包含的内容及物理数据文件: drop tablespace xxx including contents and datafiles;
这里根据ORA-29349的报错,解决办法是删除已有的表空间,再进行导入,由于须要XTTS元数据还没导入,保留数据文件,并且若是把数据文件清理掉了,数据就丢失了,迁移就会变的没有意义。因此这里选用drop tablespace xxx including contents;的方式进行删除。为了确保能保留数据文件,我进行了测试,也就是这个测试形成了下面的山路十八湾(不想被我带坑里的能够跳过,直接到第四节)
create tablespace test_drp datafile '+DATA’ size 10m autoextend off; select tablespace_name,file_name from dba_data_files where tablespace_name=' TEST_DRP' TABLESPACE_NAME FILE_NAME ------------------------------ --------------------------------------------- TEST_DRP +DATA/RACDB/DATAFILE/test_drp.456.974282309 drop tablespace TEST_DRP including contents; select tablespace_name,file_name from dba_data_files where tablespace_name=' TEST_DRP'; no rows selected
发现数据文件也是被一块儿删除掉了,这里很困惑,是否是存放在ASM里面的问题?尝试drop tablespace TEST_DRP;也是同样,会将数据文件一同删除。这里或许有大神一下就知道什么缘由了,ASM问题?其它问题?这里先卖个关子,毕竟我是要带着你们走弯路的,弯路走多了就成了直路嘛(知道缘由的请跳过)
3、sqlfile生成的ddl
既然不能删除已有的表空间,那么就采用排除已经存在的对象进行导入,貌似也没有什么大不了的事嘛,是的,在咱们平常expdp/impdp中加exclude参数确实很容易。但这里有transport_datafiles参数是不能加exclude的。
再换一种思路,排除transport_datafiles中已经导入的data_files,而后加上sqlfile生成ddl语句,经过直接执行ddl来进行导入元数据。
cat imp_xttplugin_201803.par
userid='/ as sysdba' DIRECTORY=TTSIMP DUMPFILE=exp_xttplugin_201803_%u.dmp LOGFILE=imp_xttplugin_201803.log SQLFILE=imp_xttplugin_201803.sql transport_datafiles=’xxx’,’xxx’,’xxx’,’xxx’....’xxx’
生成以后的imp_xttplugin_201803.sql部份内容:
exec SYS.DBMS_PLUGTS.NEWDATAFILE('+DATA/RACDB/ test_drp.dbf'); BEGIN sys.dbms_plugts.beginImpTablespace('TEST_DRP',6,'SYS',1,0,8192,1,127403426271554,1,22147483645,8,128,8,0,1,22147483645,8,1361893745,1,4129,802505,NULL,2966,1469671696,NULL,NULL); COMMIT; END; / BEGIN sys.dbms_plugts.checkDatafile(NULL,13618937425,10,3931648,6,10,0,0,802652,127403426271554,122486743949798,421943042,NULL,NULL,NULL); COMMIT; END; / BEGIN sys.dbms_plugts.commitPluggable; COMMIT; END; /
看着能生成对应的ddl语句,还有点小激动,在尝试手工执行的时候,我错了,依旧会报ORA-29349错误,看来要好好研读一下sys.dbms_plugts这个表的内容了,嗯,效果还不错,摸索了一些规律,将剩下的表空间元数据手工导入了。也就是“Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK“这一步经过手工导入了(过程就不描述了,毕竟是行不通的办法),接下来应该”Processing object type TRANSPORTABLE_EXPORT/TABLE“ 根据生成的ddl语句已经无法往下继续了。缘由有2个,一是语法不支持,二是在导入表空间元数据的时候,表空间的tablespace_id和datafile_id都是有关联映射的。CREATE TABLE XXX.XXX (XXX XXX) STORAGE(SEG_FILE 36 SEG_BLOCK 194 OBJNO_REUSE 13743);这个是没法直接执行的。
到这里,该想的办法都想了,还想太重建控制文件,表空间重命名等,是否是真的没有办法了?这里原本打算放弃治疗了,准备清理环境以后再一步步进行XTTS迁移(模拟测试)。但这里还有个问题,就是drop tablespace在asm里数据文件会被清理掉的缘由还没找出来。
那缘由是什么呢?(赶忙恶补drop tablespace的知识)
详见:https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9004.htm
4、测试验证
--建立非OMF管理的表空间 create tablespace test_drp datafile '+DATA/RACDB/test_drp01.dbf' size 10m autoextend off; --建立测试数据 create table scott.test_drp (id number) tablespace TEST_DRP; insert into scott.test_drp values (1); create index scott.test_drp_idx on scott.test_drp(id) tablespace TEST_DRP; --表空间置为read only alter tablespace TEST_DRP read only; --导出元数据 cat >exp_xttplugin_test_20180502.par userid='/ as sysdba' DUMPFILE=exp_xttplugin_test_20180502_%u.dmp LOGFILE=exp_xttplugin_test_20180502.log DIRECTORY=TTSEXP_TMP exclude=TABLE_STATISTICS,INDEX_STATISTICS,INDEX/STATISTICS transport_full_check=no transport_tablespaces=(TEST_DRP) --导入元数据 cat >imp_xttplugin_test_20180502.par userid='/ as sysdba' DIRECTORY=TTSEXP_TMP DUMPFILE=exp_xttplugin_test_20180502_%u.dmp LOGFILE=imp_xttplugin_test_20180502.log transport_datafiles='+DATA/RACDB/test_drp01.dbf' --模拟ORA-29349报错 impdp parfile=imp_xttplugin_test_20180502.par Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options Master table "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_TRANSPORTABLE_01": /******** AS SYSDBA parfile=imp_xttplugin_test_20180502.par Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK ORA-39123: Data Pump transportable tablespace job aborted ORA-29349: tablespace 'TEST_DRP' already exists --删除TEST_DRP表空间及包含的内容,保留数据文件 drop tablespace TEST_DRP including contents; --再次执行导入 impdp parfile=imp_xttplugin_test_20180502.par Import: Release 12.1.0.2.0 - Production on Wed May 2 16:29:28 2018 Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options Master table "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_TRANSPORTABLE_01": /******** AS SYSDBA parfile=imp_xttplugin_test_20180502.par Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK Processing object type TRANSPORTABLE_EXPORT/TABLE Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK Job "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Wed May 2 16:29:32 2018 elapsed 0 00:00:03
5、案例总结
1、XTTS迁移过程有不少须要注意的点,必定不能马虎大意,关键操做最好设置还原点(restore point)。
2、OMF管理的表空间在drop tablespace的时候是会自动清理物理数据文件的。