当我们回顾Oracle产品工具发展历程,不能不承认Exp/Imp的成功。从早期的版本到现在11g,Exp/Imp都是开发人员最常使用、也是最简单使用的数据库逻辑备份工具。
但是随着Oracle产品的不断发展和现实环境中数据海量化,Exp/Imp已经不能满足实际需要了。Oracle在10g版本中正式推出了数据泵(Data Pump),也就是Expdp/Impdp产品。在很多方面,Data Pump解决或者缓解了Exp/Imp的一些缺陷。
1、版本陷阱
经常使用Exp/Imp的朋友可能都有过这样的经历:将数据导出到本地机器上,再导入到一台新服务器上的时候,经常会报版本错误。不同的数据库服务器版本、不同的客户端版本都会影响到我们导出数据dump文件,影响我们导入操作的成功。
这样情况的本质原因有两个:一个是Exp/Imp是一个客户端工具,工具程序是驻留在客户端上的。不同版本的客户端必然带来不同的Exp/Imp操作行为,写入的Dump文件也必然有一定差异。这就考验客户端程序的兼容性。
另一个方面的原因是数据库服务器的版本兼容性。每一个版本中,Oracle推出的新特性和属性,我们很难要求低版本服务器来兼容支持。Oracle可以做到向后兼容,但是不能做到“预知未来”。
所以,在Exp/Imp的使用过程中,我们经常会讨论的问题有两个,一个是字符集的匹配,另一个就是版本导出策略。
在Data Pump的使用过程中,也会有版本差异的问题。不过,Data Pump版本的架构特点决定了版本差异会得到一定程度的解决。
与Exp/Imp工具不同的是,Data Pump是一个服务端工具,只运行在数据库服务器端。这就让Data Pump不受到客户端版本的影响。同时,Oracle考虑到版本差异的影响,也给Data Pump进行了很多额外的配置。其中,version参数就是可以解决问题的方案。
2、实验环境介绍
Data Pump从10g开始推出,所以最大版本间的差异存在于Oracle 10g与11g之间。笔者选择两个环境进行测试。
10g环境是Oracle Windows版本,创建Directory对象。
SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 – Production SQL> create directory verdmp as 'D:\verdmp'; Directory created
11g环境采用Linux版本。
SQL> select * from v$version; BANNER ---------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 – Production --创建Directory对象 [root@oracle11g /]# cd /verdmp/ [root@oracle11g verdmp]# pwd /verdmp SQL> create directory verdmp as '/verdmp'; Directory created.
3、从10g到11g
首先我们测试从10g到11g的情况。如果我们从10g中导出Dump文件,导入到11g上,有没有什么问题呢?
我们先成10g上导出dmp文件。
C:\Documents and Settings\Administrator>expdp \"/ as sysdba\" directory=verdmp dumpfile=scottdmp.dmp schemas=scott Export: Release 10.2.0.1.0 - Production on 星期六,24 11月,2012 16:08:43 Copyright (c) 2003,2005,Oracle. All rights reserved. 连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning,OLAP and Data Mining options 启动 "SYS"."SYS_EXPORT_SCHEMA_01": "/******** AS SYSDBA" directory=verdmp dumpf ile=scottdmp.dmp schemas=scott 正在使用 BLOCKS 方法进行估计... (篇幅原因,有省略……) . . 导出了 "SCOTT"."BONUS" 0 KB 0 行 已成功加载/卸载了主表 "SYS"."SYS_EXPORT_SCHEMA_01" ****************************************************************************** SYS.SYS_EXPORT_SCHEMA_01 的转储文件集为: D:\VERDMP\SCOTTDMP.DMP 作业 "SYS"."SYS_EXPORT_SCHEMA_01" 已于 16:20:03 成功完成
目录中存在导出的文件。
D:\verdmp 的目录 2012-11-24 16:08
2012-11-24 16:08 .. 2012-11-24 16:20 2,360 export.log 2012-11-24 16:20 69,062,656 SCOTTDMP.DMP 2 个文件 69,065,016 字节 2 个目录 36,759,314,432 可用字节
导出成功,使用
ftp
传导到
Linux 11g
环境。
[root@oracle11g verdmp]# ls -l total 67520 -rw-r--r-- 1 root root 2360 Nov 24 08:14 export.log -rw-r--r-- 1 root root 69062656 Nov 24 08:14 SCOTTDMP.DMP
[oracle@oracle11g ~]$ impdp userid=\'/ as sysdba\' directory=verdmp dumpfile=SCOTTDMP.DMP remap_schema=scott:test Import: Release 11.2.0.1.0 - Production on Sat Nov 24 08:17:15 2012 Copyright (c) 1982,2009,Oracle and/or its affiliates. All rights reserved. With the Partitioning,OLAP,Data Mining and Real Application Testing options Master table "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_FULL_01": userid="/******** AS SYSDBA" directory=verdmp dumpfile=SCOTTDMP.DMP remap_schema=scott:test (篇幅原因,有省略……) Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SYS"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 08:17:39
导入成功。我们得到了结论:在使用
Data Pump
时候,从低版本导出的
dmp
文件可以导入到高版本的数据库服务器上。这个过程,不需要额外的配置。
4、11g到10g
下面尝试将从11g转移到10g版本。
oracle@oracle11g ~]$ expdp userid=\'/ as sysdba\' directory=verdmp dumpfile=testdmp.dmp schemas=test reuse_dumpfiles=y Export: Release 11.2.0.1.0 - Production on Sat Nov 24 08:24:01 2012 Copyright (c) 1982,Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning,Data Mining and Real Application Testing options Starting "SYS"."SYS_EXPORT_SCHEMA_01": userid="/******** AS SYSDBA" directory=verdmp dumpfile=testdmp.dmp schemas=test reuse_dumpfiles=y Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 85.25 MB (篇幅原因,有省略……) Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /verdmp/testdmp.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at 08:24:43
导出文件成功,将
dmp
文件传输到
10g
环境去导入。
D:\verdmp>dir 驱动器 D 中的卷没有标签。 卷的序列号是 2294-1384 D:\verdmp 的目录 2012-11-24 17:00
2012-11-24 17:00 .. 2012-11-24 16:20 2,656 SCOTTDMP.DMP 2012-11-24 17:00 69,103,616 testdmp.dmp 3 个文件 138,168,632 字节 2 个目录 36,689,879,040 可用字节 --导入文件 D:\verdmp>impdp \"/ as sysdba\" directory=verdmp dumpfile=testdmp.dmp Import: Release 10.2.0.1.0 - Production on 星期六,2012 17:02:19 Copyright (c) 2003,OLAP and Data Mining options ORA-39001: 参数值无效 ORA-39000: 转储文件说明错误 ORA-39142: 版本号 3.1 (在转储文件 "D:\verdmp\testdmp.dmp" 中) 不兼容
报错,明显是版本错误。解决问题的方法,就是在导出
expdp
的时候,使用
version
参数限制
文件的格式。官方的文档中,对
参数如下: