1、基本環境sql
源庫:數據庫
DB_NAME:racdb(rac) HOSTNAME:note1、note2 PUBLIC IP:172.16.1.7、172.16.1.8 STORAGE:ASM oracle
OS_VERSION:RedHat6.5 ORACLE_VERSION:11.2.0.4.0app
目標庫:ide
DB_NAME:testdb(single instance) HOSTNAME:iscsi-asm IP:172.16.1.20 STORAGE:file system OS_VERSION:RedHat6.5 ORACLE_VERSION:11.2.0.4.0測試
遷移表空間:MYTESTspa
2、DATAPUMP遷移表空間日誌
1、源數據庫建立測試表空間orm
SQL> create tablespace mytest datafile'+data' size 100m; Tablespace created. SQL> create user mytest identified bymytest123 default tablespace mytest; User created. SQL> grant connect,resource to mytest; Grant succeeded. SQL> create table mytest.t1 as select *from dba_segments; Table created. SQL> select count(1) from mytest.t1; COUNT(1) ---------- 4795
2、確認源數據庫的表空間是否自包含server
SQL> exec dbms_tts.transport_set_check('mytest',true,true); PL/SQL procedure successfully completed. SQL> select * from transport_set_violations; no rows selected
查看檢查的結果,無輸出說明該表空間是自包含的,也就是說該表空間的對象沒有依賴其它表空間。接下來,我在測試表mytest.t1上建個索引,存儲在users表空間上,再看看查詢transport_set_violations的結果。
SQL> alter user mytest quota unlimited on users; User altered. SQL> create index mytest.t1_owner_idx on mytest.t1(owner) tablespace users; Index created. SQL> exec dbms_tts.transport_set_check('mytest',true,true); PL/SQL procedure successfully completed. SQL> select * from transport_set_violations; VIOLATIONS -------------------------------------------------------------------------------- ORA-39907: Index MYTEST.T1_OWNER_IDX in tablespace USERS points to table MYTEST. T1 in tablespace MYTEST.
從查詢transport_set_violations的結果中能夠看出,該表空間的對象T1_OWNER_IDX這個索引依賴其它表空間USERS,因此它不是自包含的,利用datapump和rman的方式都是不支持,所以,可以使用alter table/index move的方式不在自包含的表空間的對象移動到同一表空間以後再遷移表空間。這裏我將索引T1_OWNER_IDX先刪除。
3、確認平臺是否兼容
SQL> select t.* fromv$transportable_platform t,v$database d where t.platform_name =d.platform_name; PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT -------------------------------------------------- -------------- 13 Linuxx86 64-bit Little
目前源庫和目標庫都是RedHat 6.5,相同的OS,不存在跨平臺的狀況,因此這裏簡單的說一下就行,可經過查詢v$transportable_platform視圖的endian_format進行對比,若相同則說明能夠進行跨平臺的遷移。
補充:源端數據庫版本和目標端數據庫版本的問題,根據datapump的特性高進低出,因此高版本到低版本應該是不支持的,而低到高是沒問題的。
4、將表空間置爲read only狀態
SQL> alter tablespace mytest read only; Tablespace altered.
5、導出表空間metadata
SQL> create directory zwdir as'/u/app/oracle/zwdir'; Directory created. [oracle@note1 zwdir]$ expdp \'\/ assysdba\' directory=zwdirdumpfile=mytest.dmp nologfile=y transport_tablespaces=mytest
6、將表空間置爲read write狀態
SQL> alter tablespace mytest read write; Tablespace altered.
7、cp源庫數據文件和dmp到目標庫
這裏須要注意的是源庫數據文件是存儲在ASM中的,須要從ASM中先拷貝到本地文件系統上,在此過程當中須要將數據文件的所屬用戶由grid修改成oracle。拷貝過程這裏就不作記錄了。
8、目標端執行導入
SQL> create user mytest identified bymytest123; User created. SQL> grant connect,resource to mytest; Grant succeeded.
先須要創建一個相同的用戶,否則會報以下的錯誤:
ORA-39123: Data Pump transportabletablespace job aborted
ORA-29342: user MYTEST does not exist inthe database
在導入以前,須要考慮源庫與目標庫的字符集是否相同,若是不一樣,則須要修改成相同的字符集;還須要考慮兩個數據庫之間的BLOCK_SIZE是否一致,若不一致,須要修改DB_nK_CACHE_SIZE的大小。
[oracle@iscsi-asm ~]$ impdp \'\/ assysdba\' directory=zwdirdumpfile=mytest.dmp nologfile=ytransport_datafiles='/u/app/oracle/oradata/datafile/MYTEST.279.935793141'
這裏是從ASM到文件系統,讀者能夠思考下:從文件系統到ASM的遷移、ASM到ASM之間的遷移,其實都是差很少的。
9、進行驗證
SQL> select count(1) from mytest.t1; COUNT(1) ---------- 4795 SQL> alter tablespace mytest read write; Tablespace altered.
10、Datapump遷移表空間的總結:
transport_tablespace是須要知足許多條件的,從上能夠知道,須要字符集相同,表空間是自包含的,若是跨平臺的話,還需確認endian_format是否一致。最關鍵的是須要遷移的表空間須要在READ ONLY狀態,能讀不能寫,這對於7*24環境的系統而言,是沒有辦法接受的,那麼是否有辦法解決該問題呢?有的,那就是RMAN TRANSPORT TABLESPACE。
3、RMAN遷移表空間
一、RMAN備份數據庫
源庫須要備份整庫和全部的歸檔日誌,由於除了目標表空間的備份之外,RMAN還須要SYSTEM、SYSAUX以及UNDO表空間的備份,若是任意一個表空間的備份不存在,則就會致使RMAN-06019: 沒法轉換表空間名稱的錯誤。
RMAN> backup database plus archivelog format '/u/app/oracle/zwdir/full_bak_%T_%t.bak'; RMAN> transport tablespace mytesttablespace destination '/u/app/oracle/zwdir' auxiliary destination'/u/app/oracle/zwdir/mytest';
此時須要遷移的表空間數據文件,dmp文件,導入腳本等都在/u/app/oracle/zwdir目錄下,而/u/app/oracle/zwdir/mytest創建的輔助實例的臨時文件都會被刪除。觀察一下生成的導入腳本文件:
這裏能夠發現從ASM存儲到文件系統上數據文件使用了OMF的方式進行管理。
二、CP生成的文件到目標庫
[oracle@note1 zwdir]$ scp -ro1_mf_mytest_db3jhv2w_.dbf dmpfile.dmp impscrpt.sql 172.16.1.20:/u/app/oracle/zwdir/ oracle@172.16.1.20's password: o1_mf_mytest_db3jhv2w_.dbf 100% 100MB 100.0MB/s 00:01 dmpfile.dmp 100% 112KB 112.0KB/s 00:00 impscrpt.sql 100%2094 2.0KB/s 00:00
三、導入目標庫
SQL> @impscrpt.sql Directory created. Directory created. PL/SQL procedure successfully completed. Directory dropped. Directory dropped.
4、進行驗證
SQL> select tablespace_name,status fromdba_tablespaces where tablespace_name='MYTEST'; TABLESPACE_NAME STATUS ------------------------------------------------ MYTEST READ ONLY SQL> select count(1) from mytest.t1; COUNT(1) ---------- 4795
五、RMAN遷移表空間的總結:
對比datapump遷移表空間,rman遷移表空間更加簡單實用,能夠說是rman將datapump遷移的方式進行腳本的集成。雖然,以上個人操做步驟很簡單,datapump該考慮的條件,使用rman也是同樣須要考慮的,字符集相同,表空間是自包含的,若是跨平臺的話,還需確認endian_format一致,兩個數據庫之間的BLOCK_SIZE也要一致等。
參考官網相關文章:
TransportingTablespaces Between Databases
http://docs.oracle.com/cd/E11882_01/server.112/e25494/tspaces013.htm
CreatingTransportable Tablespace Sets
http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmttbsb.htm