資料泵 TTS(傳輸表空間技術)

張衝andy發表於2016-12-06

1、源庫準備環境
--建立被傳輸的表空間
create tablespace tts logging datafile '/home/oracle/app/oradata/orcl/tts01.dbf' 
size 40m autoextend on next 10m maxsize 100m extent management local;

create tablespace ttsind logging datafile '/home/oracle/app/oradata/orcl/ttsind01.dbf' 
size 40m autoextend on next 10m maxsize 100m extent management local;

--建立使用者,並將表空間作為預設表空間
SQL> create user tts identified by tts default tablespace tts;
SQL> grant connect,resource to tts;
SQL> grant select on dba_objects to tts;
[oracle@11g ~]$ sqlplus tts/tts
--在該表空間建立表,用於測試
create table datapump as select * from dba_objects;
delete from datapump where object_id is null;
create index ind_datapump on datapump(object_id) tablespace ttsind;
create table datapump02 as select * from dba_objects;
create bitmap index ind_datapump02 on datapump02(object_type) tablespace ttsind;
commit;
SQL> select count(*) from datapump;
COUNT(*)
----------
74886

SQL> select count(*) from datapump02;
COUNT(*)
----------
74888

2. 源庫資訊統計
--查詢表空間有哪些使用者 (sys使用者)
SQL> select distinct owner from dba_segments where tablespace_name in ('TTS','TTSIND') ;

OWNER
------------------------------
TTS
--計算某個表空間所包含物件的大小
select 'SIZE_TABELSPACE' NAME,sum(user_bytes)/1024/1024 SIZE_M from dba_data_files where tablespace_name='TTS' UNION ALL select 'SIZE_OBJECT' NAME,sum(nvl(bytes,0))/1024/1024 SIZE_M from user_segments where tablespace_name='TTS'; 
NAME SIZE_M
--------------- ----------
SIZE_TABELSPACE 39
SIZE_OBJECT
-- 檢視錶空間內物件的個數
select segment_type,count(1) as"NUM" from dba_segments where tablespace_name in ('TTS','TTSIND') group by segment_type;
SEGMENT_TYPE NUM
------------------ ----------
TABLE 2
INDEX 2

--檢視DBLINK 資訊:

SQL> select owner,object_name,object_type from dba_objects where object_type='DATABASELINK';

--檢視JOB 資訊:

SQL> select count(*) from dba_jobs where schema_user in ('DATAPUMP'); ('','')

3. 檢查源、目標平臺Endianness
--在源資料庫平臺上:
SQL> col PLATFORM_NAME for a40
SQL> 
SELECT d.PLATFORM_NAME, ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;

PLATFORM_NAME ENDIAN_FORMAT
---------------------------------------- --------------
Linux x86 64-bit Little

--在目標資料庫平臺上:
SQL> col PLATFORM_NAME for a40
SQL> 
SELECT d.PLATFORM_NAME, ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;

PLATFORM_NAME ENDIAN_FORMAT
---------------------------------------- --------------
Linux x86 64-bit Little

由於源和目標平臺的Endianness一致,可以省去convert這一步。
--檢視 transportable_platform 支援總表
select * from v$transportable_platform;
4、檢查源庫表空間是否自包含
SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('TTS',true);
PL/SQL 過程已成功完成。
SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;
未選定行
說明表空間是自包含的。
SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('TTSIND',true);
PL/SQL procedure successfully completed.

SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;

VIOLATIONS
--------------------------------------------------------------------------------
ORA-39907: Index TTS.IND_DATAPUMP in tablespace TTSIND points to table TTS.DATAP
UMP in tablespace TTS.

ORA-39907: Index TTS.IND_DATAPUMP02 in tablespace TTSIND points to table TTS.DAT
APUMP02 in tablespace TTS.

5、產生傳輸表空間集 (源庫)
SQL>CREATE DIRECTORY dump_dir as '/home/oracle/dump_dir';
[oracle@11g ~]$ mkdir -p /home/oracle/dump_dir
SQL>grant read,write on directory dump_dir to SYSTEM;
將表空間置為只讀。
SQL> alter tablespace tts read only;
表空間已更改。
SQL> alter tablespace ttsind read only;
表空間已更改。
-- 檢查表空間是否為read only
SQL> select tablespace_name,status from dba_tablespaces where status='READ ONLY';

TABLESPACE_NAME STATUS
------------------------------ ---------
TTS READ ONLY
TTSIND READ ONLY
使用資料泵匯出傳輸表空間的後設資料
[oracle@11g dump_dir]$ expdp \'sys/oracle as sysdba\' DIRECTORY=dump_dir DUMPFILE=tts_%U.dmp transport_tablespaces=tts,ttsind transport_full_check=y logfile=exp_tts.log parallel=1

Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at Wed Mar 11 14:20:02 2015 elapsed 0 00:00:59

注:如果Endianness不一致,還需要使用RMAN進行轉換表空間的資料檔案。
若兩個平臺位元組序不相同,透過RMAN命令將源庫中需要傳輸的表空間所對應的資料檔案轉換:
>rman target /
RMAN> convert tablespace ‘表空間名’
to platform=’目標平臺‘
db_file_name_convert=’資料檔案位置’,’轉換後的位置’;
如:將HP-UX (64-bit) Big 轉換成Linux IA (64-bit) Little
RMAN> convert tablespace ‘test1’ 
to platform=’Linux IA (64-bit)’ db_file_name_convert=’/u01/oradata/test01.dbf’,’/temp/test01.dbf’;

6、目標庫建立相關環境
SQL>CREATE DIRECTORY dump_dir as '/home/oracle/dump_dir';
[oracle@11g ~]$ mkdir -p /home/oracle/dump_dir
SQL>grant read,write on directory dump_dir to SYSTEM;

7. 將Transportable Tablespace set 傳送到Target端

--檢視源庫表空間資料檔案路徑
SQL> select name from v$datafile where ts# in (select ts# from v$tablespace where name in ('TTS','TTSIND'));

NAME
--------------------------------------------------------------------------------
/home/oracle/app/oradata/orcl/tts01.dbf
/home/oracle/app/oradata/orcl/ttsind01.dbf
(1)將表空間tts , ttsind 對應的資料檔案copy到Target 對應的ORADATA目錄下。
(2)將expdp 匯出的表空間metadta 資料copy 到Target 端的backup 目錄下
[oracle@11g dump_dir]$ scp tts_01.dmp 10.100.25.13:/home/oracle/dump_dir/
oracle@10.100.25.14's password: 
tts_01.dmp 100% 132KB 132.0KB/s 00:00

[oracle@11g orcl]$ scp tts01.dbf 10.100.25.13:/home/oracle/app/oradata/orcl/
oracle@10.100.25.14's password: 
tts01.dbf 100% 40MB 40.0MB/s 00:01 
[oracle@11g orcl]$ scp ttsind01.dbf 10.100.25.13:/home/oracle/app/oradata/orcl/
oracle@10.100.25.14's password: 
ttsind01.dbf 100% 40MB 40.0MB/s 00:01

--將源庫表空間改為 read writer
SQL> alter tablespace ttsind read write;
Tablespace altered.

SQL> alter tablespace tts read write;
Tablespace altered.

8、匯入表空間 (目標庫)
-- 目標庫檢查是否擁有TTS表空間內所有使用者
SQL> select username from dba_users where username in ('TTS');
--在目標資料庫中,如果沒有,建立相應的使用者。
SQL> create user tts identified by tts;
User created.

SQL> grant connect,resource to tts;
Grant succeeded.

--在Target 系統上Import 表空間的metadata。
[oracle@11g dump_dir]$ impdp \'sys/oracle as sysdba\' DIRECTORY=dump_dir DUMPFILE=tts_%U.dmp transport_datafiles=/home/oracle/app/oradata/orcl/tts01.dbf,/home/oracle/app/oradata/orcl/ttsind01.dbf parallel=1 logfile=exp_tts.log

Job "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Wed Mar 11 18:18:33 2015 elapsed 0 00:00:14

注意:
(1)這裡transport_datafiles 寫的是datafile的全路徑, 也可以用transport_datafiles來對資料檔案進行重新命名和移動位置。
(2)如果檔案很多,也可以寫入個配置檔案裡。 匯入時透過PARFILE引數來指定。

--將被匯入的表空間置為read write。
SQL> alter tablespace tts read write;
Tablespace altered.
SQL> alter tablespace ttsind read write;
Tablespace altered.

9、核查物件
SQL> select segment_type,count(1) as"NUM" from dba_segments where tablespace_name in ('TTS','TTSIND') group by segment_type;

SEGMENT_TYPE NUM
------------------ ----------
TABLE 2
INDEX 2


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

相關文章