expdp和impdp的实践

来源:互联网 发布:女生发型 知乎 编辑:程序博客网 时间:2024/05/01 23:40

导入导出我们经常用的是exp/imp命令,确实比较方便,但也有局限,例如需要导入导出的表空间名相同、schema名需要相同。


最近就碰到了这么个问题,此时expdp和impdp这种数据泵的导入导出工具就起了作用。


待导出表和索引的空间名:

SQL> select distinct tablespace_name from user_tables;
TABLESPACE_NAME
---------------
QXU_IMC_DATA

SQL> select distinct tablespace_name from user_indexes;
TABLESPACE_NAME
---------------
QXU_IMC_DATA
QXU_IMC_INDEX
INIT_IMC_DATA


1、导出

首先需要创建dumpfile的路径:

create directory test_dump='C:/dump';

导出:expdp user/pwd directory=test_dump dumpfile=qxuimc.dmp schemas=qxuimc logfile=exp_qxuimc.log

C:/dump下就会找到导出的dmp文件和日志文件。


2、导入

将dmp文件放到待导入的库服务器上。

同样,若之前没有建过dumpfile路径,此时也需要建。

impdp user/pwd DIRECTORY=test_dump DUMPFILE=qxuimc.dmp REMAP_SCHEMA=qxuimc:*** LOGFILE=imp_test.log REMAP_TABLESPACE=QXU_IMC_DATA:***,QXU_IMC_INDEX:***,INIT_IMC_DATA:***

此处使用REMAP_SCHEMA表示将导出的schema映射为新的名称。REMAP_TABLESPACE表示将导出的tablespace映射为新的名称。


说明:

1、dumpfile可以使用select * from dba_directories;查看。

2、导入之前需要删除所有和导入对象相同的对象,例如function、package、table、index、sequence、role等,否则导入时会忽略这部分内容的导入,将错误记录到日志中。

3、impdp和expdp的参数还有很多,这里只用了最常用的,网上也有很多资料。

4、关于导入导出的版本问题,之前写的一篇文章介绍过:

http://blog.csdn.net/bisal/article/details/17350155

Export client compatibility:
Always use a version of the EXPORT utility that is equal to the lowest version of either the source or the target database.
导出客户端兼容性:建议使用和源数据库或目标数据库中最低版本一致的EXPORT工具版本。
Import client compatibility:
Always use a version of the IMPORT utility that is equal to the version of the target database.
导入客户端兼容性:建议使用和目标数据库版本一致的IMPORT工具版本。

我这里导出的版本是10g,导入的是11g。expdp使用的是10g的,impdp使用的是11g,符合上面的标准。

对于和这种情况相反的场景,expdp支持version参数指定目标数据库的版本。

1 0
原创粉丝点击