---
title: "数据泵 EXPDP 导出工具的使用"
author: "csstome"
date: "2010-10-07T18:10:00Z"
tags: []
slug: "expdp"
draft: false
lastmod: "2011-11-08T19:45:01Z"
id: 1244627
url: "https://csstome.iteye.com/blog/1244627"
---

--=================================

--数据泵 EXPDP 导出工具的使用

--=================================

对于Oracle 数据库之间的导入导出，可以使用Oracle提供的导入导出工具EXP/IMP来实现。EXP/IMP是Oracle早期提供的数据导入导出工具。在Oracle 10g 中，提供了高速导入导出数据泵IMPDP，EXPDP，本文主要讲述EXPDP的用法。

关于IMPDP的用法，请参照：数据泵IMPDP 导入工具的使用

一、数据泵的体系结构

数据泵是一个基于服务器端的高速导入导出工具，通过dbms\_datapump包来调用

提供expdp，impdp，以及基于Web页面来实现导入导出

提供两种数据数据方式方式：直接路径、外部表

可以定制数据泵作业，以及从作业中分离和重新附加到作业

服务器端的数据泵是直接访问数据文件与SGA，不必通过会话进行访问

数据泵进程

对Unix系统而言，数据泵进程为expdp，impdp

对Windows系统而言，数据泵进程为expdp.exe，impdp.exe

启动一个DataPump作业，至少会启动下列两个进程，一个Data Pump Master(DMnn)，一个或多个工作进程(DWnn)，主进程控制工作进程

如果多个DataPump作业同时运行，那么每个作业都具有自己的DMnn进程以及自己的DWnn进程

如果设置了并行技术，则每个DWnn进程可以使用两个或多个并行执行服务器(名称为Pnnn)

DataPump生成下列三种形式的文件

SQL文件：描述指定作业所包含对象的若干DDL语句

转储文件：即包含数据和元数据的文件

日志文件：用于记录导出时的相关信息

目录

用于设置导入导出文件所在或存放的位置create directory dump\_scott as /home/oracle/dump/scott';

可以通过dba\_directories来查看系统中已创建的目录 select * from dba\_directories;

对于创建的目录必须授予用户读写目录的权限 grant read,write on directory dump\_scott to scott;

二、数据泵的优点

在Oracel 10g 中提供的数据泵，较之i时代的导入导出工具(imp,exp)，除了能实现imp/exp的功能之外，提供了更好的性能， 下面是数据泵的优点

为数据及数据对象提供更细微级别的选择性(使用exclude,include,content参数)

可以设定数据库版本号(主要是用于兼容老版本的数据库系统)

并行执行

预估导出作业所需要的磁盘空间(使用estimate\_only参数)

支持分布式环境中通过数据库链接实现导入导出

支持导入时重新映射功能(即将对象导入到新的目标数据文件，架构，表空间等)

支持元数据压缩及数据采样

三、数据泵程序接口及模式

数据泵导入导出接口如下

命令行接口

参数文件

交互式命令行接口

数据库控制台

数据泵导入导出模式

整个数据库

架构

表

表空间

传输表空间

四、导出工具expdp

1\. 它是操作系统下一个可执行的文件存放目录/ORACLE\_HOME/bin

\[oracle@oradb bin]$ ls -lh expdp

-rwxr-x--x 1 oracle oinstall 174K Sep 13 20:01 expdp

expdp导出工具将数据库中数据备份压缩成一个二进制系统文件.可以在不同OS间迁移

expdb支持三种模式：

a. 表模式： 导出用户所有表或者指定的表

b. 用户模式：导出用户所有对象以及对象中的数据

c. 导出表空间：导出数据库中特定的表空间

d. 整个数据库： 导出数据库中所有对象

使用expdp-? 可以查看expdp命令的用法并启动交互进程，也可使用expdp -help来查看更详细的帮助信息

\[oracle@oradb bin]$ expdp -?

abort\_step Undocumented feature

access\_method Data Access Method - default is Automatic

attach Attach to existing job - no default)''

compression Content to export: default is METADATA\_ONLY

content Content to export: default is ALL

directory Default directory specification

dumpfile dumpfile names: format is (file1,...) default is expdat.dmp

encryption\_password Encryption key to be used

estimate Calculate size estimate: default is BLOCKS

estimate\_only Only estimate the length of the job: default is N

exclude Export exclude option: no default

filesize file size: the size of export dump files

flashback\_time database time to be used for flashback export: no default

flashback\_scn system change number to be used for flashback export: no default

full indicates a full mode export

include export include option: no default

ip\_address IP Address for PLSQL debugger

help help: display description on export parameters, default is N

job\_name Job Name: no default)''

keep\_master keep\_master: Retain job table upon completion

log\_entry logentry

logfile log export messages to specified file

metrics Enable/disable object metrics reporting

mp\_enable Enable/disable multi-processing for current session

network\_link Network mode export

nologfile No export log file created

package\_load Specify how to load PL/SQL objects

parallel Degree of Parallelism: default is 1

parallel\_threshold Degree of DML Parallelism

parfile parameter file: name of file that contains parameter specifications

query query used to select a subset of rows for a table

sample Specify percentage of data to be sampled

schemas schemas to export: format is '(schema1, .., schemaN)'

silent silent: display information, default is NONE

status Interval between status updates

tables Tables to export: format is '(table1, table2, ..., tableN)'

tablespaces tablespaces to transport/recover: format is '(ts1,..., tsN)'

trace Trace option: enable sql\_trace and timed\_stat, default is 0

transport\_full\_check TTS perform test for objects in recovery set: default is N

transport\_tablespaces Transportable tablespace option: default is N

tts\_closure\_check Enable/disable transportable containment check: def is Y

userid user/password to connect to oracle: no default

version Job version: Compatible is the default

Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 14:22:56

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Username:

2\. 导出工具expdp非交互式命令行方式的例子

a.基于表模式的导出

SQL&gt; create directory dump\_scott as '/home/oracle/dump/scott';

Directory created.

SQL&gt; select * from dba\_directories;

OWNER DIRECTORY\_NAME DIRECTORY\_PATH

\------------------------------ ------------------------------ --------------------------------------------------

SYS DUMP\_SCOTT /home/oracle/dump/scott

SQL&gt; grant read,write on directory dump\_scott to scott;

Grant succeeded.

SQL&gt; !

\[oracle@oradb /]$ mkdir /home/oracle/dump

\[oracle@oradb /]$ mkdir /home/oracle/dump/scott

\[oracle@oradb ~]$ expdp scott/tiger directory=dump\_scott dumpfile=dumptab.dmp /

&gt; logfile=scott.log tables=dept,emp

Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 14:55:23

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

Starting "SCOTT"."SYS\_EXPORT\_TABLE\_01": scott/\*\*\*\*\*\*\*\*/ directory=dump\_scott dumpfile=dumptab.dmp logfile=scott.log tables=dept,emp

Estimate in progress using BLOCKS method...

Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA

Total estimation using BLOCKS method: 128 KB

Processing object type TABLE\_EXPORT/TABLE/TABLE

Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX

Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS

Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/REF\_CONSTRAINT

Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS

. . exported "SCOTT"."DEPT" 5.656 KB 4 rows

. . exported "SCOTT"."EMP" 7.820 KB 14 rows

Master table "SCOTT"."SYS\_EXPORT\_TABLE\_01" successfully loaded/unloaded

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

Dump file set for SCOTT.SYS\_EXPORT\_TABLE\_01 is:

/home/oracle/dump/scott/dumptab.dmp

Job "SCOTT"."SYS\_EXPORT\_TABLE\_01" successfully completed at 14:55:56

--后台中DMnn,DWnn进程为启动DataPump是产生的进程

\[oracle@oradb /]$ ps -ef | grep ora\_d

oracle 3445 1 0 14:19 ? 00:00:00 ora\_dbw0\_orcl

oracle 3461 1 0 14:19 ? 00:00:00 ora\_d000\_orcl

\[oracle@oradb ~]$ ls -lh /home/oracle/dump/scott

total 132K

-rw-r----- 1 oracle oinstall 124K Sep 20 14:55 dumptab.dmp

-rw-r--r-- 1 oracle oinstall 1.4K Sep 20 14:55 scott.log

b. 基于用户模式导出

\[oracle@oradb /]$ expdp scott/tiger directory=dump\_scott dumpfile=dumpscott.dmp schemas=scott

Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 15:08:55

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

Starting "SCOTT"."SYS\_EXPORT\_SCHEMA\_01": scott/\*\*\*\*\*\*\*\*/ directory=dump\_scott dumpfile=dumpscott.dmp schemas=scott

Estimate in progress using BLOCKS method...

Processing object type SCHEMA\_EXPORT/TABLE/TABLE\_DATA

Total estimation using BLOCKS method: 192 KB

Processing object type SCHEMA\_EXPORT/PRE\_SCHEMA/PROCACT\_SCHEMA

Processing object type SCHEMA\_EXPORT/TABLE/TABLE

Processing object type SCHEMA\_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS

Processing object type SCHEMA\_EXPORT/TABLE/COMMENT

Processing object type SCHEMA\_EXPORT/TABLE/CONSTRAINT/REF\_CONSTRAINT

Processing object type SCHEMA\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS

. . exported "SCOTT"."DEPT" 5.656 KB 4 rows

. . exported "SCOTT"."EMP" 7.820 KB 14 rows

. . exported "SCOTT"."SALGRADE" 5.585 KB 5 rows

. . exported "SCOTT"."BONUS" 0 KB 0 rows

Master table "SCOTT"."SYS\_EXPORT\_SCHEMA\_01" successfully loaded/unloaded

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

Dump file set for SCOTT.SYS\_EXPORT\_SCHEMA\_01 is:

/home/oracle/dump/scott/dumpscott.dmp

Job "SCOTT"."SYS\_EXPORT\_SCHEMA\_01" successfully completed at 15:09:23

c.基于表空间导出

\[oracle@oradb /]$ expdp scott/tiger directory=dump\_scott dumpfile=users1.dmp,user2.dmp /

&gt; compression tablespaces=users

Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 15:17:35

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

Starting "SCOTT"."SYS\_EXPORT\_TABLESPACE\_01": scott/\*\*\*\*\*\*\*\*/ directory=dump\_scott dumpfile=users1.dmp,user2.dmp compression tablespaces=users

Estimate in progress using BLOCKS method...

Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA

Total estimation using BLOCKS method: 192 KB

Processing object type TABLE\_EXPORT/TABLE/TABLE

Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX

Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS

Processing object type TABLE\_EXPORT/TABLE/COMMENT

Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/REF\_CONSTRAINT

Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS

. . exported "SCOTT"."DEPT" 5.656 KB 4 rows

. . exported "SCOTT"."EMP" 7.820 KB 14 rows

. . exported "SCOTT"."SALGRADE" 5.585 KB 5 rows

. . exported "SCOTT"."BONUS" 0 KB 0 rows

Master table "SCOTT"."SYS\_EXPORT\_TABLESPACE\_01" successfully loaded/unloaded

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

Dump file set for SCOTT.SYS\_EXPORT\_TABLESPACE\_01 is:

/home/oracle/dump/scott/users1.dmp

Job "SCOTT"."SYS\_EXPORT\_TABLESPACE\_01" successfully completed at 15:17:51

\[oracle@oradb /]$ ls -lh /home/oracle/dump/scott

total 524K

-rw-r----- 1 oracle oinstall 4.0K Sep 20 15:17 compression.dmp

-rw-r----- 1 oracle oinstall 224K Sep 20 15:09 dumpscott.dmp

-rw-r----- 1 oracle oinstall 124K Sep 20 14:55 dumptab.dmp

-rw-r--r-- 1 oracle oinstall 1.6K Sep 20 15:17 export.log

-rw-r--r-- 1 oracle oinstall 1.4K Sep 20 14:55 scott.log

-rw-r----- 1 oracle oinstall 4.0K Sep 20 15:17 user2.dmp

-rw-r----- 1 oracle oinstall 148K Sep 20 15:17 users1.dmp

d. 导出整个数据库，且使用并行导出方式

\[oracle@oradb /]$ expdp scott/tiger directory=dump\_scott dumpfile=full20\_%u.dmp parallel=4 full=y

Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 15:24:02

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

ORA-31631: privileges are required

ORA-39161: Full database jobs require privileges

\[oracle@oradb /]$ sqlplus /nolog

SQL\*Plus: Release 10.2.0.1.0 - Production on Mon Sep 20 15:24:16 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL&gt; conn /as sysdba

Connected.

Grant succeeded.

SQL&gt; !

\[oracle@oradb /]$ expdp scott/tiger directory=dump\_scott dumpfile=full20\_%u.dmp parallel=6 full=y

--中间过程省略

\[oracle@oradb dump]$ ls -lh ./scott/fu*

-rw-r----- 1 oracle oinstall 19M Sep 20 15:36 ./scott/full20\_01.dmp

-rw-r----- 1 oracle oinstall 22M Sep 20 15:34 ./scott/full20\_02.dmp

-rw-r----- 1 oracle oinstall 18M Sep 20 15:36 ./scott/full20\_03.dmp

-rw-r----- 1 oracle oinstall 15M Sep 20 15:36 ./scott/full20\_04.dmp

-rw-r----- 1 oracle oinstall 5.4M Sep 20 15:36 ./scott/full20\_05.dmp

-rw-r----- 1 oracle oinstall 196K Sep 20 15:33 ./scott/full20\_06.dmp

\[oracle@oradb dump]$ ps -ef | grep ora\_d

oracle 3445 1 0 14:19 ? 00:00:01 ora\_dbw0\_orcl

oracle 3461 1 0 14:19 ? 00:00:00 ora\_d000\_orcl

oracle 23443 1 4 15:32 ? 00:00:01 ora\_dm00\_orcl

oracle 23494 1 23 15:32 ? 00:00:08 ora\_dw01\_orcl

oracle 23673 1 11 15:33 ? 00:00:02 ora\_dw02\_orcl

oracle 23675 1 16 15:33 ? 00:00:03 ora\_dw03\_orcl

oracle 23677 1 8 15:33 ? 00:00:01 ora\_dw04\_orcl

oracle 23679 1 5 15:33 ? 00:00:00 ora\_dw05\_orcl

oracle 23681 1 2 15:33 ? 00:00:00 ora\_dw06\_orcl

oracle 23696 2416 0 15:33 pts/1 00:00:00 grep ora\_d

五、数据泵的监控

1.查询dba\_directories获得所创建的目录

2.可以查询dba\_datapump\_jobs来查看数据泵作业的运行情况，也可以利用ATTACH重新连接上还在进行的JOB

每个datapump可以通过job\_name 参数来指定作业名称，如未指定，则系统使用默认的作业名称,如下面的视图中为SYS\_EXPORT\_FULL\_01

通过v$session\_longops也可以查看长时间运行的datapump job的具体内容

SQL&gt; select owner\_name owr,job\_name jbn,operation ope,job\_mode jbm,state,degree,

2 attached\_sessions atts,datapump\_sessions dats

3 from dba\_datapump\_jobs;

OWR JBN OPE JBM STATE DEGREE ATTS DATS

\---------- -------------------- -------------------- --------------- ---------- ---------- ---------- ----------

SCOTT SYS\_EXPORT\_FULL\_01 EXPORT FULL COMPLETING 2 1 2

SQL&gt; select sid, serial#,session\_type

2 from v$session s, dba\_datapump\_sessions d

3 where s.saddr = d.saddr;

SID SERIAL# SESSION\_TYPE

\---------- ---------- --------------

143 10 DBMS\_DATAPUMP

149 37 MASTER

132 3 WORKER

136 3 WORKER

135 4 WORKER

141 5 WORKER

128 2 WORKER

142 4 WORKER

3.监控数据泵的逻辑备份程度

SELECT sid, serial#, context, sofar, totalwork,

ROUND(sofar/totalwork\*100,2) "%\_COMPLETE"

FROM v$session\_longops

WHERE opname LIKE '%EXP%'

AND totalwork != 0

AND sofar &lt;&gt; totalwork;

SID SERIAL# CONTEXT SOFAR TOTALWORK %\_COMPLETE

130 33 0 54 70 77.14

六、expdp的常用参数

1.content: 该选项用于指定要导出的内容.默认值为ALL

CONTENT={ALL | DATA\_ONLY | METADATA\_ONLY}

expdp scott/tiger schemas=scott content=all

expdp scott/tiger tables=emp content=data\_only directory=dump\_scott dumpfile=empdata.dmp(只导出对象数据)

expdp scott/tiger tables=emp content=metadata\_only directory=dump\_scott dumpfile=empmd.dmp(只有定义信息)

2.estimate: 指定估算被导出表所占用磁盘空间分方法.默认值是blocks

expdp scott/tiger directory=dump\_scott dumpfile=dba\_object.dmp tablespaces=users estimate=statistics

expdp scott/tiger directory=dump\_scott dumpfile=dba\_object.dmp tablespaces=users estimate=blocks

3.extimate\_only:指定是否只估算导出作业所占用的磁盘空间,默认值为N

expdp scott/tiger schemas=scott estimate\_only=y

设置为Y时,导出作用只估算对象所占用的磁盘空间,而不会执行导出作业,

为N时,不仅估算对象所占用的磁盘空间,还会执行导出操作.

4.exclude:该选项用于指定执行操作时释放要排除对象类型或相关对象

exclude=view

exclude=package

exclude=index:"like 'EMP%'

object\_type用于指定要排除的对象类型,name\_expr用于指定要排除的具体对象.exclude和include不能同时使用

expdp scott/tiger schemas=scott exclude=view dumpfile=a9.dmp

include = object\_type\[:"name\_expr"]

5.filesize:指定导出文件的最大尺寸,默认为,(表示文件尺寸没有限制)

6.flashback\_scn: 前提闪回功能开启

expdp scott/tiger tables=emp dumpfile=e2.dmp flashback\_scn=4284715

如果闪回的时间点该对象结构发生变化，将报错（比如该对象没有创建或者ddl操作)

7.flashback\_time：指定导出特定时间点的表数据

expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dmp FLASHBACK\_TIME="TO\_TIMESTAMP(’-08-2004 14:35:00’,’DD-MM-YYYY HH24:MI:SS’)"

windows下：

C:/&gt;expdp scott/tiger DIRECTORY=dump\_dir DUMPFILE=a.dmp

flashback\_time=/"TO\_TIMESTAMP('06-04-2010 11:24:26', 'DD-MM-YYYY HH24:MI:SS')/"

8.query导出查询得到的结果集

query=scott.emp :"where deptno = 30 and sal &gt; 3500"

9.sample 使用该参数进行对导出的数据进行采样

sample="scott"."emp":20

expdp scott/tiger directory=dump\_scott dumpfile=sam.dmp sample=30

10.dumpfile 指定导出时的文件名

dumpfile=scott\_tb.dmp

dumpfile=scott\_tb\_%u.dmp %u 用于扩展导出的文件名，固定长度为个字符，从开始递增，使用并行导出时建议指定该参数

七、更多参考

[Oracle 冷备份](http://blog.csdn.net/robinson_0612/archive/2010/08/05/5791597.aspx)

[SPFILE错误导致数据库无法启动](http://blog.csdn.net/robinson_0612/archive/2010/07/29/5774795.aspx)

[Oracle 用户、对象权限、系统权限](http://blog.csdn.net/robinson_0612/archive/2010/06/23/5688875.aspx)

[Oracle 角色、配置文件](http://blog.csdn.net/robinson_0612/archive/2010/06/23/5688997.aspx)

[Oracle 联机重做日志文件(ONLINE LOG FILE)](http://blog.csdn.net/robinson_0612/archive/2010/07/20/5749556.aspx)

[Oracle 控制文件(CONTROLFILE)](http://blog.csdn.net/robinson_0612/archive/2010/07/15/5737527.aspx)

[Oracle 表空间与数据文件](http://blog.csdn.net/robinson_0612/archive/2010/05/20/5611738.aspx)

[Oracle 归档日志](http://blog.csdn.net/robinson_0612/archive/2010/08/03/5784713.aspx)