---
title: "imp/exp impdp/expdp"
author: "werwolf"
date: "2010-09-03T13:21:32Z"
tags: []
categories: ["数据库"]
slug: "imp-exp-impdp-expdp"
draft: false
lastmod: "2010-09-03T13:21:50Z"
id: 754435
url: "https://werwolf.iteye.com/blog/754435"
---

EXP常规模式、EXP直接路径模式和EXPDP三种方式导出的性能对比  
1.首先是EXP的常规路径导出：  
exp zhejiang/zhejiang file=/data1/zj\_regular.dmp buffer=20480000  
常规EXP导出方式执行了1小时24分钟。

2.直接路径导出方式：  
exp zhejiang/zhejiang file=/data1/zj\_direct.dmp buffer=20480000  
recordlength=65535 direct=y  
直接路径导入用时18分钟，比常规路径导出速度有一个明显的提高。

 

3.数据泵的导出速度。  
expdp zhejiang/zhejiang dumpfile=zj\_datapump.dp directory=d\_test schemas=zhejiang  
数据泵的导出时间仅用了14分钟，比直接路径导入方式还快了20%多。而且观察三个导出文件的大小可以发现，导出速度越快对应的文件也越小，其中数据泵的导出方式得到的文件要比EXP方式小将近1.5G。

IMP和IMPDP导入性能对比  
1.IMP的导入速度：  
imp zhejiang/zhejiang file=/data1/zj\_regular.dmp full=y buffer=20480000 log=/data1/zj\_regular.log  
IMP导入花费了3小时17分钟，

2.IMPdp的导入速度：  
impdp zhejiang/zhejiang DUMPFILE=zj\_datapump.dp DIRECTORY=d\_test FULL=y LOGFILE=zj\_datapump.log  
数据泵的导入操作居然花了3个小时8分钟的时间，和IMP的导入速度十分接近，看来并非所有情况下都像Oracle描述的那样，数据泵的导入比普通导入效率有大幅度的提高。

上面一篇文章的测试中发现IMPDP的导入速度和IMP导入速度相差无几。而Oracle在介绍数据泵的时候，提到IMPDP的导入速度最高是IMP的10倍。不过好在IMPDP还是可以优化调整的，那就是通过设置PARALLEL来提高IMPDP的并行度。  
首先还是看一下CPU的数量：

SQL&gt; show parameter cpu

由于数据库服务器的CPU个数为2，下面尝试设置PARALLEL为2来进行导入  
impdp zhejiang/zhejiang DUMPFILE=zj\_datapump.dp DIRECTORY=d\_test FULL=y LOGFILE=zj\_datapump.log parallel=2

采用并行度为2的导入方式，发现速度果然提高了很多。并行度为1的导入速度是3小时8分钟，而现在用了不到2个半小时。  
由于并行度设置不应该超过CPU数的2倍，因此尝试平行度3和4的导入，导入时间和并行度2十分接近。看来已经无法再使用通过提高并行度的方法来提高性能了。

1.先看直接导出的性能：

$ expdp zhejiang/zhejiang directory=d\_test dumpfile=zhejiang.dp  
整个导出操作大概用了14分半，

2.尝试使用并行度2进行导出，这时仍然设置一个导出的数据文件：  
$ expdp zhejiang/zhejiang directory=d\_test dumpfile=zhejiang\_p2\_1file.dp parallel=2

整个导入过程不到14分钟，不过这个性能的提升实在不是很明显。不过这是有原因的，由于设置了并行度，两个进程在同时执行导出操作，但是二者要将导出的数据写入同一个数据文件中，因此必然会导致资源的争用

3.仍然使用并行度2，但是同时设置两个数据文件再次检查导出性能：  
$ expdp zhejiang/zhejiang directory=d\_test dumpfile=zhejiang\_p2\_2file1.dp,zhejiang\_p2\_2file2.dp parallel=2

这次导出仅仅用了10分半，导出的效率大大的提高。

4.测试一下并行度4，分别导出到4个数据文件中：  
用了9分钟整导出完成，设置成并行度4仍然可以获得一定的性能提升，但是并不明显了，这主要是由于整个性能的瓶颈已经不是单个进程的处理能力，多半性能的瓶颈已经变成了磁盘IO瓶颈，此时单单靠增加并行度已经无法明显提升性能了。

 

 

 

 

 

1：把用户usera的对象导到用户userb,用法区别在于fromuser=usera touser=userb ,remap\_schema='usera':'usera' 。例如

imp system/passwd fromuser=usera touser=userb file=/oracle/exp.dmp log=/oracle/exp.log;  
impdp system/passwd directory=expdp dumpfile=expdp.dmp remap\_schema='usera':'userb' logfile=/oracle/exp.log;

2：更换表空间，用exp/imp的时候，要想更改表所在的表空间，需要手工去处理一下，  
如alter table xxx move tablespace\_new之类的操作。  
用impdp只要用remap\_tablespace='tabspace\_old':'tablespace\_new'

3:当指定一些表的时候，使用exp/imp 时，tables的用法是 tables=('table1','table2','table3')。  
expdp/impdp的用法是tables='table1','table2','table3'

4:  
是否要导出数据行  
exp　（ROWS=Y 导出数据行，ROWS=N 不导出数据行）  
expdp content（ALL:对象＋导出数据行，DATA\_ONLY：只导出对象，METADATA\_ONLY：只导出数据的记录）

A: exp/imp的使用 (服务器端和客户端都可以执行。并且备份文件可以在客户端产生。)

*exp user/password@servicename file=dump.dmp*  
*imp user/password@servicename fromuser=fuser touser=tuser file=dump.dmp*

2: expdp/impdp的使用 （服务器端和客户端都可以执行。备份文件只能存在服务器里面 。）

I：在使用expdp导出时在Oracle需要定义目录变量，在导出的时候需要制定这个变量。如果可以，你可以为每个用户都建立一个单独的备份目录。  
SQL&gt;create directory dmpdir\_user1 as '/home/oracle/backup';  
SQL&gt;grant read,write on directory dmpdir\_user1 to user1;  
对了，操作系统内必须创建这个目录。在SQL命令行下，并不会产生这个目录的。  
\[oracle@kook ~]$ mkdir backup  
如果你没有制定这个目录的话，默认exp导出存放的目录是$HOME/rdbms/log里面。至少我的是这样。很奇怪，为什么在这里。

II：执行导出导入命令  
*expdp user1/password@servicename schemas=user1 directory=dmpdir\_user1 dumpfile=user1.dmp*  
*impdp user2/password@servicename directory=dmpdir\_user1 dumpfile=user1.dmp remap\_schema=user1:user2 remap\_tablespace=user1ts:user2ts*  
使用expdp/impdp最大的好处可以让我转换表空间。而exp/imp这个是不支持的。处理起来非常麻烦。