如何使用exp以传输表空间的方式将其导出

来源:岁月联盟 编辑:zhuzhu 时间:2008-08-12
 

有时候,可以使用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