XTTS跨平臺遷移impdp導入元數據報ORA-29349

一、遷移環境

源庫:AIX-Based Systems (64-bit)11.1.0.7.0  rac
目標庫:Linux x86 64-bit 12.1.0.2 rac 

 

二、導入元數據報錯

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 & 

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 & 

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、查詢已經導入的元數據

--發現已經導入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步驟,已經有部分元數據導入了,再次發起導入已經存在的就會存在衝突。

 

三、尋找解決辦法

1ORA-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、刪除表空間的坑

我們日常常用的刪除表空間的語句有如下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問題?其它問題?這裏先賣個關子,畢竟我是要帶着大家走彎路的,彎路走多了就成了直路嘛(知道原因的請跳過

 

3sqlfile生成的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_iddatafile_id都是有關聯映射的。CREATE TABLE XXX.XXX (XXX XXX) STORAGE(SEG_FILE 36 SEG_BLOCK 194 OBJNO_REUSE 13743);這個是無法直接執行的。

 

到這裏,該想的辦法都想了,還想過重建控制文件,表空間重命名等,是不是真的沒有辦法了?這裏本來打算放棄治療了,準備清理環境之後再一步步進行XTTS遷移(模擬測試)。但這裏還有個問題,就是drop tablespaceasm裏數據文件會被清理掉的原因還沒找出來。

 

那原因是什麼呢?(趕緊惡補drop tablespace的知識)

12321.jpg.png

詳見:https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9004.htm

 

四、測試驗證

--創建非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

 五、案例總結

1XTTS遷移過程有很多需要注意的點,一定不能馬虎大意,關鍵操作最好設置還原點(restore point)。

2OMF管理的表空間在drop tablespace的時候是會自動清理物理數據文件的。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章