有時候,可以使用exp將以傳輸表空間的方式將其導出,傳輸表空間是一種機制,用來把一個數據庫上的格式數據文件附加到另一個數據庫。
需要註意:
對於導出文件dmp來說,Oracle實現了跨平臺的處理,即在任何一個可運行的平臺上,都能使用imp將其導入,但是對於表空間所包含的數據文件而言,各個平臺上是不一樣的,包含不能通過簡單的復制來處理。數據文件不是獨立於OS的。
傳輸表空間移動數據速度非常快。
使用前提:
1.源和目標數據庫使用相同的字符集。
2.目標數據庫不能有和源表空間相同的表空間
3.源和目標數據庫擁有相同的塊大小
4.必須傳輸自包含的對象集
5.源和目標數據庫運行的硬件平臺必須相同
這裏以linux下Oracle9.2.0.4為例,簡要介紹一下使用:
1.創建表空間,並生成數據
sqlplus "/ as sysdba"
create tablespace hexiong datafile ?/hexiong.dbf size 1M;
create user hexiong identified by hexiong default tablespace hexiong;
grant connect, resource to hexiong;
conn hexiong/hexiong
create table t as select * from all_objects;
2.檢查一下表空間是否齊備:
exec sys.dbms_tts.transport_set_check('hexiong', TRUE);
PL/SQL procedure successfully completed.
SQL> select * from sys.transport_set_violations;
no rows selected
這表示該表空裏的對象集是自包含的(對象及其索引都在此表空間中)
3.設定表空間為只讀
alter tablespace hexiong read only;
4.開始exp
SQL> host exp userid=\'sys/change_on_install as sysdba\' transport_tablespace=y tablespaces=(hexiong) file=/u01/app/oracle/exphexiong.dmp
Export: Release 9.2.0.4.0 - Production on ÐÇÆÚÈÕ 7ÔÂ 30 19:27:00 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
For tablespace HEXIONG ...
. exporting cluster definitions
. exporting table definitions
. . exporting table T
. exporting referential integrity constraints
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.
5.將導出的文件以及相關源表空間的數據文件拷到目標數據庫或機器上
導出文件:/u01/app/oracle/exphexiong.dmp
數據文件:
SQL> select b.name from v$tablespace a, v$datafile b where a.ts#=b.ts# and a.name='HEXIONG';
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/bjlnx1/hexiong.dbf
6.進入目標機器上,創建對應表空間的用戶,不必指定缺省表空間
設exphexiong.dmp以及hexiong.dbf的位置都在/home/oradba上
cd /home/oradba
SQL>create user hexiong identified by hexiong;
7.導入:
imp file=exphexiong.dmp userid=\'sys/change_on_install as sysdba\' transport_tablespace=y datafiles=/home/oradba/hexiong.dbf