expdp/impdp 遷移表空間

babyyellow發表於2012-06-05
cmsdb 的拆庫已經完成,但是應為是在standby 的基礎上拆的庫,導致sid一致,無法再同一臺機器上多一套standby 

我們嘗試了建立不同例項的standby 庫,都告失敗,只剩下2個方法可行了,一個是nid 修改資料庫名字,一個是建新庫,然後把資料庫轉到新庫裡面。 

nid 我們在生產庫上還沒有實施過的經驗,雖然 oracle 很早就提供了這個工具,但還是有其不確定性。

建新庫,轉資料,用expdp/impdp 導資料就太慢了,總共要處理40g左右的資料,停機時間還是比較長。於是測試了表空間遷移的方法

測試證明可行性還是很高的。


下面是測試步驟 


1。 首先要檢查要遷移的表空間是否支援表空間遷移
       限制主要包括: 表空間物件的自包含性, 表空間中,不能有system,sys等使用者的物件。

      首先表空間設只讀: 
       alter tablespace pchouse_test read only ; 

       執行檢查指令碼:
1SYS AS SYSDBA at test745 > EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('PCHOUSE_TEST', TRUE,TRUE);
2 
3PL/SQL procedure successfully completed.
4 
5SYS AS SYSDBA at test745 >
6SYS AS SYSDBA at test745 > SELECT * FROM TRANSPORT_SET_VIOLATIONS;
7 
8  no rows selected
     系統表  TRANSPORT_SET_VIOLATIONS  沒有資料說明該表空間是支援遷移的。如果有資料,則要在遷移前把這些物件的處理好,
      
2 。 匯出meta資料
01       [oracle@test740_5 oracle]$ expdp lsliang/lsliang directory=dmp_dir dumpfile=p.dat  TRANSPORT_TABLESPACES=pchouse_test TRANSPORT_FULL_CHECK=Y
02 
03Export: Release 10.2.0.4.0 - 64bit Production on D??úò?, 21 6??, 2010 11:50:22
04 
05Copyright (c) 2003, 2007, Oracle.  All rights reserved.
06 
07Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
08With the Partitioning, OLAP, Data Mining and Real Application Testing options
09Starting "LSLIANG"."SYS_EXPORT_TRANSPORTABLE_01":  lsliang/******** directory=dmp_dir dumpfile=p.dat TRANSPORT_TABLESPACES=pchouse_test TRANSPORT_FULL_CHECK=Y
10Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
11Processing object type TRANSPORTABLE_EXPORT/TABLE
12Processing object type TRANSPORTABLE_EXPORT/INDEX
13Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
14Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
15Processing object type TRANSPORTABLE_EXPORT/COMMENT
16Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/REF_CONSTRAINT
17Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
18Master table "LSLIANG"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
19******************************************************************************
20Dump file set for LSLIANG.SYS_EXPORT_TRANSPORTABLE_01 is:
21  /data1/oracle/p.dat
22Job "LSLIANG"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 11:50:38
3. 把匯出metadata檔案以及表空間對應的資料檔案copy到目標機器相應的資料目錄下,資料目錄不要求一致。
1[oracle@test740_5 oracle]$ scp p.dat  /data/oracle/oradata/test745/PCHOUSE_TEST.dbf  oracle@192.168.74.6:/data/oracle/oradata/test746
2oracle@192.168.74.6's password:
3p.dat                                                                                             100% 2104KB   2.1MB/s   00:00   
4PCHOUSE_TEST.dbf                                                                                  100%  300MB  42.9MB/s   00:07   
5[oracle@test740_5 oracle]$
4. 到目標機上匯入meta data資料 
  
    首先要要在目標機器上指定一個使用者,新建一個使用者或者指定一個已有的使用者

我們新建了一個
01SQL> create user pchouse_app identified by pchouse_app
02  2  default tablespace pchouse_test;
03create user pchouse_app identified by pchouse_app
04*
05ERROR at line 1:
06ORA-00959: tablespace 'PCHOUSE_TEST' does not exist
07 
08 
09SQL> create user pchouse_app identified by pchouse_app;
10 
11User created.
12 
13SQL> grant dba to pchouse_app;
14 
15Grant succeeded.
16 
17SQL> exit
metadata資料匯入:
01[oracle@test740_6 oracle]$ impdp system/system  directory=dmp_dir dumpfile=p.dat  transport_datafiles=/data/oracle/oradata/test746/PCHOUSE_TEST.dbf  remap_schema=pchouse_app:pchouse_app
02 
03Import: Release 10.2.0.4.0 - 64bit Production on D??úò?, 21 6??, 2010 11:50:38
04 
05Copyright (c) 2003, 2007, Oracle.  All rights reserved.
06 
07Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
08With the Partitioning, OLAP, Data Mining and Real Application Testing options
09Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
10Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/******** directory=dmp_dir dumpfile=p.dat transport_datafiles=/data/oracle/oradata/test746/PCHOUSE_TEST.dbf remap_schema=pchouse_app:pchouse_app
11Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
12Processing object type TRANSPORTABLE_EXPORT/TABLE
13Processing object type TRANSPORTABLE_EXPORT/INDEX
14Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
15Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
16Processing object type TRANSPORTABLE_EXPORT/COMMENT
17Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/REF_CONSTRAINT
18Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
19Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 11:50:50
20 
21[oracle@test740_6 oracle]$
5檢查下
01SQL> select table_name from dba_tables where wner='PCHOUSE_APP';
02 
03TABLE_NAME
04------------------------------
05OPERATION
06TBLAPPROVE
07TBLAPPUPFILE
08TBLARTICLE
09TBLARTICLEAUTO
10TBLARTICLEBRIEF
11TBLBACKUPLOG
12TBLBACKUPTEMPLATE
13TBLARTICLECOPY
14TBLARTICLEPRODUCT
15TBLARTICLE_ARCH
16 
17TABLE_NAME
18------------------------------
19.................
20... 此處省略n行
21 
22SQL>
23SQL> select count(*) from pchouse_app.tbltext ;
24 
25  COUNT(*)
26----------
27     14739
檢查資料時 ok 的

6 。 在目標庫上把表空間設為讀寫狀態 源庫上的也要這麼做
1SQL> alter tablespace pchouse_test read write ;
2 
3Tablespace altered.
4 
5SQL>
如果採用表空間傳輸的方式來遷移資料,那麼主要的費時間的地方,就取決於資料檔案的scp的速度了。

over !!! 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-731990/,如需轉載,請註明出處,否則將追究法律責任。

相關文章