对于expdp 转换表空间的学习,是通过网上资料再加上自己整理,没有冒犯原作者的意思,请大家谅解。

   EXPDP/IMPDP由于采用了DBMS_METADATA来获取源数据,因此在转化表空间的时候可以完整的全部替换。解决了分区表、LOB表以及包含OVERFLOW段的索引组织表的表空间转化问题。
   

   下面是我摘抄的一个说明:

说明:

REMAP_SCHEMA可以定义用户的切换,其格式为:
remap_schema=old_schema_name:new_schema_name

REMAP_TABLESPACE可以定义切换对象的不同表空间,其格式为:
remap_tablespace=old_tablespace_name:new_tablespace_name

 

在使用impdp时,会发现,有很多参数选项与imp不同,比如说,找不到了fromuser和touser参数,也找不到了ignore参数,indexes等参数也不再存在。

当然这些功能都还在,而且更加强大,impdp有了不少新的替代参数。
以下三个参数极大的增强了用户转换及表空间转换的操作:
REMAP_DATAFILE        Redefine datafile references in all DDL statements.
REMAP_SCHEMA          Objects from one schema are loaded into another schema.
REMAP_TABLESPACE      Tablespace object are remapped to another tablespace.

REMAP_SCHEMA可以定义用户的切换,其格式为:
remap_schema=old_schema_name:new_schema_name

REMAP_TABLESPACE可以定义切换对象的不同表空间,其格式为:
remap_tablespace=old_tablespace_name:new_tablespace_name

以前类似IGNORE的忽略创建错误,可以使用CONTENT参数:
CONTENT               Specifies data to load where the valid keywords are:
                              (ALL), DATA_ONLY, and METADATA_ONLY.

如果数据结构已经存在可以指定CONTENT=DATA_ONLY,仅导入数据。

而关于索引的排除,可以使用EXCLUDE参数:
EXCLUDE               Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.

IMPDP导入时忽略索引可以使用类似: EXCLUDE=CONSTRAINT EXCLUDE=INDEX

如果导入时遇到如下错误,就需要调整REMAP_SCHEMA参数:


遇到如下错误,那就需要制定REMAP_TABLESPACE参数:
ORA-00959: tablespace 'SMS_MT' does not exist

今天使用的参数是:
impdp sms4/sms4 dumpfile=08.dmp directory=impdp TABLES=smsmg REMAP_SCHEMA=SMS:SMS4 REMAP_TABLESPACE=SMS_MT:SMS CONTENT=DATA_ONLY PARALLEL=8 EXCLUDE=CONSTRAINT EXCLUDE=INDEX

 

 

下面是我做的测试:

首先我创建了一个表空间:


SQL>  create tablespace xysoul datafile '/opt/oracle/app/oracle/oradata/soul/xysoul.dbf' size 100M autoextend on next 10M maxsize 2048m;

又创建了两个用户:

SQL> create user test identified by test;

User created.

SQL> create user xysoul identified by xysoul;

User created.  我暂时给与了用户dba的权限

连接到:SQL> conn test/test

Connected.

创建一个表:

SQL> create table t_partition (id number,name varchar2(30)) partition by range (id) (partition p1 values less than(100) tablespace users,partition p2 values less than (maxvalue) tablespace example);

Table created.

 

 

SQL> insert into t_partition select rownum,table_name from dba_tables;

 

2777 rows created.

创建一个转储目录:

SQL> conn / as sysdba

Connected.

SQL> create directory exp_dir as '/soft';

 

Directory created.

 

SQL> grant read,write on directory exp_dir to test;

 

Grant succeeded.

 

SQL> grant read,write on directory exp_dir to xysoul;

 

Grant succeeded.

导出的命令:

 expdp test/test directory=exp_dir dumpfile=test.dmp logfile=test.log

导入的命令:分区表两个在不同的表空间上,

impdp xysoul/xysoul directory=exp_dir dumpfile=test.dmp remap_schema=test:xysoul remap_tablespace=users:xysoul remap_tablespace=example:xysoul

 

以上只是自己简单的测试,如果遗漏或者不同的地方,请大家共同探讨