Datapump 是一个服务,基于大容量数据迁移的结构,用来取代旧的 import/export 工具。旧的 import/export 工具仍然可用,但不支持所有的 Oracle 10g 和 11g 的功能。这个新的工具名为 expdp 和 impdp。
本文内容本文介绍 Oracle 10g 及之后版本导出/入工具的步骤,内容如下:
- 开始使用 datapump 导出
- 创建数据库目录
- 再次尝试导出
- 导入另一个数据库
- 网络导入
- 从 PL/SQL 调用
- Oracle 11g Release 1 (11.1) Data Pump 导出和导入概述
- Oracle 11g Release 1 (11.1) Data Pump 导出和导入模式
- 参考资料
- 修改记录
开始用 datapump 导出
$ expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
Export: Release 10.2.0.1.0 - 64bit Production on Friday, 31 March, 2006 11:36:07
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39087: directory name DMPDIR is invalid
说明:
- "dmpdir" 为导出目录;
- "scott.dmp" 为导出的 datadump 文件;
- scott 用户下的表在默认表空间 USERS 和临时表空间 TEMP 下。所以这个命令将 scott 用户把自己的表(对象)导出来;
- 因为,Oracle 已经有这两个表空间,所以,直接导入即可。但是,如果是自己创建的表空间,就先要创建这个表空间,然后再导入。
导出失败了!因为,我们需要先创建目录!
创建数据库目录
执行如下命令,创建一个数据库导出目录。该目录必须指向一个同一个服务器的有效目录作为数据库:
SQL> CREATE DIRECTORY dmpdir AS '/opt/oracle';
Directory created.
SQL> GRANT read, write ON DIRECTORY dmpdir TO scott;
Grant succeeded.
说明:
- "dmpdir" 为导出目录,"/opt/oracle" 为数据库路径(也可以操作系统的绝对路径,如"d:db_backup");
- 导出目录授权。让 scott 用户对该目录可读写。这样,scott 用户才能正常访问该目录,将数据库内容和导出的日志文件放在这里。
备注:Oracle 从 Oracle 10g R2 开始,引入了一个称为 "DATA_PUMP_DIR" 的默认目录,如下所示:
SQL> SELECT directory_path FROM dba_directories WHERE directory_name = 'DATA_PUMP_DIR';
DIRECTORY_PATH
--------------------------------------------------------------------------------
/app/oracle/product/10.2.0/rdbms/log/
再次尝试导出
$ expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
Export: Release 10.2.0.1.0 - 64bit Production on Friday, 31 March, 2006 11:41:02
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/******** DIRECTORY=dmpdir DUMPFILE=scott.dmp
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 175.2 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC
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/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/JOB
. . exported "SCOTT"."BIGEMP" 145.2 MB 3670016 rows
. . exported "SCOTT"."DEPT" 5.656 KB 4 rows
. . exported "SCOTT"."EMP" 7.820 KB 14 rows
. . exported "SCOTT"."ORD_CHARGE_TAB" 5.296 KB 2 rows
. . exported "SCOTT"."SALGRADE" 5.585 KB 5 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
. . exported "SCOTT"."NEWOBJECT1_T" 0 KB 0 rows
. . exported "SCOTT"."T1" 0 KB 0 rows
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
/app/oracle/scott.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 11:44:50