Oracle数据泵expdp的version参数跨版本(转)
一、问题描述与分析:
今天碰到个问题,需求是将Oracle 11g版本的数据用expdp数据泵导出,再把数据导入至Oracle 10版本中,是否可以?一个不错的问题,没做过肯定不能乱说啦。首先我们来猜一下,我认为低版本导入高版本是可以的,高版本导入低版本就不一定了,但是我们想想oracle公司会让11g的库的内容无法导入到低版本吗?答案在实验中,接下来我们就立即做个这个实验,进行验证。
二、实验
1.低版本—>高版本 环境:低版本10g(10.2.0.1.0) 高版本11g(11.2.0.1.0) 猜测:可以 结论:可以
(1)10g环境中创建测试用户sam,并赋予权限
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jan 5 19:06:25 2016
Copyright (c) 1982, 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
[email protected] >select username from dba_users where username='SAM';
no rows selected
[email protected] >create user sam identified by sam;
User created.
[email protected] >grant connect,resource to sam;
Grant succeeded.
(2)创建测试表test及数据
[email protected] >conn sam/sam
Connected.
[email protected] >create table test (id int,name varchar2(10));
Table created.
[email protected] >insert into test values (1,'sam');
1 row created.
[email protected] >commit;
Commit complete.
[email protected] >select * from test;
ID NAME
---------- ----------
1 sam
(3)创建导出数据时用到的directory并赋(读\写)权限
[email protected] >conn / as sysdba
Connected.
[email protected] >create directory test as '/home/oracle';
Directory created.
[email protected] >grant write,read on directory test to sam;
Grant succeeded.
(4)expdp导出10g数据库中sam用户数据
[[email protected] ~]$ expdp sam/[email protected] directory=test dumpfile=test.dmp
Export: Release 10.2.0.1.0 - 64bit Production on Friday, 08 January, 2016 10:32:37
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 "SAM"."SYS_EXPORT_SCHEMA_01": sam/********@ocm10g directory=test dumpfile=test.dmp
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 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
. . exported "SAM"."TEST" 5.234 KB 1 rows
Master table "SAM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SAM.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/test.dmp
Job "SAM"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:32:44
[[email protected] ~]$ ls -l test.dmp
-rw-r----- 1 oracle oinstall 143360 Jan 8 10:32 test.dmp
(5)创建11g环境,导入数据时用到的directory,创建SAM用户
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 8 10:34:48 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[email protected] >select username from dba_users where username='SAM';
no rows selected
[email protected] >create user sam identified by sam;
User created.
[email protected] >grant connect,resource to sam;
Grant succeeded.
(6)将test.dmp文件导入11g数据库
[[email protected] ~]$ impdp system/[email protected] directory=test dumpfile=test.dmp
Import: Release 11.2.0.1.0 - Production on Fri Jan 8 11:03:37 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/********@ocm11g directory=test dumpfile=test.dmp
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SAM"."TEST" 5.234 KB 1 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 11:03:39
(7)检查用户及导入数据
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 8 11:03:54 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[email protected] >conn sam/sam
Connected.
[email protected] >select * from test;
ID NAME
---------- ----------
1 sam
2.高版本—>低版本 环境:高版本11g(11.2.0.1.0) 低版本10g(10.2.0.1.0) 猜测:不成 结论:可以,要使用version参数
(1)11g库中创建测试用户suzzy,并赋予权限
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 8 11:14:37 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[email protected] >select username from dba_users where username='SUZZY';
no rows selected
[email protected] >create user suzzy identified by suzzy;
User created.
[email protected] >grant connect,resource to suzzy;
Grant succeeded.
(2)创建测试表test1及数据
[email protected] >conn suzzy/suzzy
Connected.
[email protected] >create table test1 (id int,name varchar2(10));
Table created.
[email protected] >insert into test1 values (1,'suzzy');
1 row created.
[email protected] >commit;
Commit complete.
[email protected] >select * from test1;
ID NAME
---------- ----------
1 suzzy
(3)给用户suzzy赋予对导出目录test的读写权限
[email protected] >grant write,read on directory test to suzzy;
Grant succeeded.
(4)导出11g库中suzzy用户及数据
[[email protected] ~]$ expdp suzzy/[email protected] directory=test dumpfile=test1.dmp
Export: Release 11.2.0.1.0 - Production on Fri Jan 8 11:29:14 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SUZZY"."SYS_EXPORT_SCHEMA_01": suzzy/********@ocm11g directory=test dumpfile=test1.dmp
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 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
. . exported "SUZZY"."TEST1" 5.429 KB 1 rows
Master table "SUZZY"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SUZZY.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/test1.dmp
Job "SUZZY"."SYS_EXPORT_SCHEMA_01" successfully completed at 11:29:29
(5)创建10g数据库中用户并赋予权限,包括导入时用到的directory
[email protected] >select username from dba_users where username='SUZZY';
no rows selected
[email protected] >create user suzzy identified by suzzy;
User created.
[email protected] >grant connect,resource to suzzy;
Grant succeeded.
[email protected] >grant read,write on directory test to suzzy;
Grant succeeded.
(6)将test1.dmp文件导入10g数据库,此时会报错,原因是由于版本不符合要求,此时需要使用expdp中version参数
[[email protected] ~]$ impdp suzzy/[email protected] directory=test dumpfile=test1.dmp
Import: Release 10.2.0.1.0 - 64bit Production on Friday, 08 January, 2016 11:35:06
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-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-39142: incompatible version number 3.1 in dump file "/home/oracle/test1.dmp"
翻译:
ORA-39001: 参数值无效
ORA-39000: 转储文件说明错误
ORA-39142: 版本号 3.1 (在转储文件 "/home/oracle/test1.dmp" 中) 不兼容
(7)增加version参数,重新从11g库中导出dump文件
[[email protected] ~]$ expdp suzzy/[email protected] directory=test dumpfile=test2.dmp version=10.2.0.1.0
Export: Release 11.2.0.1.0 - Production on Fri Jan 8 14:01:34 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SUZZY"."SYS_EXPORT_SCHEMA_01": suzzy/********@ocm11g directory=test dumpfile=test2.dmp version=10.2.0.1.0
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 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
. . exported "SUZZY"."TEST1" 5.304 KB 1 rows
Master table "SUZZY"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SUZZY.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/test2.dmp
Job "SUZZY"."SYS_EXPORT_SCHEMA_01" successfully completed at 14:01:50
(8)将加参数version导出后的test2.dmp文件导入10g数据库
[[email protected] ~]$ impdp suzzy/[email protected] directory=test dumpfile=test2.dmp
Import: Release 10.2.0.1.0 - 64bit Production on Friday, 08 January, 2016 14:03:47
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
Master table "SUZZY"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SUZZY"."SYS_IMPORT_FULL_01": suzzy/********@ocm10g directory=test dumpfile=test2.dmp
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SUZZY"."TEST1" 5.304 KB 1 rows
Job "SUZZY"."SYS_IMPORT_FULL_01" successfully completed at 14:03:48
(9)验证用户及数据
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jan 8 14:04:27 2016
Copyright (c) 1982, 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
[email protected] >conn suzzy/suzzy
Connected.
[email protected] >select * from test1;
ID NAME
---------- ----------
1 suzzy
三、version参数说明
(1)官方文档:
VERSION
Default: COMPATIBLE
Purpose
Specifies the version of database objects to be exported (that is, only database objects and attributes that are compatible with the specified release will be exported). This can be used to create a dump file set that is compatible with a previous release of Oracle Database. Note that this does not mean that Data Pump Export can be used with releases of Oracle Database prior to Oracle Database 10g release 1 (10.1). Data Pump Export only works with Oracle Database 10g release 1 (10.1) or later. The VERSION parameter simply allows you to identify the version of the objects being exported.
Syntax and Description
VERSION=[COMPATIBLE | LATEST | version_string]
The legal values for the VERSION parameter are as follows:
-
COMPATIBLE - This is the default value. The version of the metadata corresponds to the database compatibility level. Database compatibility must be set to 9.2 or higher.
-
LATEST - The version of the metadata corresponds to the database release.
-
version_string - A specific database release (for example, 11.2.0). In Oracle Database 11g, this value cannot be lower than 9.2.
Database objects or attributes that are incompatible with the specified release will not be exported. For example, tables containing new datatypes that are not supported in the specified release will not be exported.
Restrictions
-
Exporting a table with archived LOBs to a database release earlier than 11.2 is not allowed.
-
If the Data Pump Export VERSION parameter is specified along with the TRANSPORT_TABLESPACES parameter, then the value must be equal to or greater than the Oracle Database COMPATIBLE initialization parameter.
(2)说明
根据官方文档,我们可以看到version参数有3个选项可以选,分别为compatible、latest、version_string,默认选项是compatible,这个选项是导出的元数据与数据库的版本兼容性级别一致,例如我导出的数据库兼容性是11.2.0.0.0 那么导出时就是11.2.0.0.0,这个很好理解。latest选项是最高版本与数据库版本保持一致,这个基本很少用到。version_string是指定具体数据库版本的字符串,这个很常用,在清楚自己数据库版本时,可以直接指定导出兼容版本,注意在11g的版本中,该参数指定版本不能小于9.2。
再有就是数据库对象与属性也要对该版本支持,否则不会被导出,例如,包含新数据类型的表不支持指定的版本不会被导出。
限制:
低于11.2版本,不允许导出带有archived LOBs表(通过字面上未能太理解,在群里做了些咨询,也没有最终的结果,不过还是有些收获,11g中导出的包含securefile lob的表,导入到10g中会丢失到该特性,见 四)
如果数据泵version参数随着TRANSPORT_TABLESPACES指定参数,那么version值必须等于或大于Oracle数据库初始化参数兼容。
四、关于securefile lob字段导出导入测试
1.创建测试表
11g环境:
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jan 13 18:58:37 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[email protected] >show parameter db_securefile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_securefile string PERMITTED
[email protected] >conn sam/sam
Connected.
[email protected] >create table t1(a clob) lob (a) store as securefile (compress low cache nologging);
Table created.
[email protected] >insert into t1 select rpad('a',4000,'*') str from dual connect by rownum<=10;
10 rows created.
[email protected] >commit;
Commit complete.
1、导出数据
[[email protected] ~]$ expdp sam/[email protected] directory=test dumpfile=test_lob8.dmp version=10.2.0.1.0
Export: Release 11.2.0.1.0 - Production on Wed Jan 13 19:10:42 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SAM"."SYS_EXPORT_SCHEMA_01": sam/********@ocm11g directory=test dumpfile=test_lob8.dmp version=10.2.0.1.0
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 576 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/STATISTICS/TABLE_STATISTICS
. . exported "SAM"."T1" 83.51 KB 11 rows
. . exported "SAM"."T_CLOB" 83.54 KB 10 rows
. . exported "SAM"."TEST_LOB" 5.382 KB 1 rows
. . exported "SAM"."TEST" 5.296 KB 1 rows
Master table "SAM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SAM.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/test_lob8.dmp
Job "SAM"."SYS_EXPORT_SCHEMA_01" successfully completed at 19:10:58
2、导入10g环境
[[email protected] ~]$ impdp sam/[email protected] directory=test dumpfile=test_lob8.dmp
Import: Release 10.2.0.1.0 - 64bit Production on Wednesday, 13 January, 2016 19:13:15
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
Master table "SAM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SAM"."SYS_IMPORT_FULL_01": sam/********@ocm10g directory=test dumpfile=test_lob8.dmp
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SAM"."T1" 83.51 KB 11 rows
. . imported "SAM"."T_CLOB" 83.54 KB 10 rows
. . imported "SAM"."TEST_LOB" 5.382 KB 1 rows
. . imported "SAM"."TEST" 5.296 KB 1 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SAM"."SYS_IMPORT_FULL_01" successfully completed at 19:13:16
3、对比10g,11g库中t1表结构
(11g)
[email protected] > select dbms_metadata.get_ddl('TABLE','T1','SAM') from dual;
DBMS_METADATA.GET_DDL('TABLE','T1','SAM')
--------------------------------------------------------------------------------
CREATE TABLE "SAM"."T1"
("A" CLOB) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE
DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
LOB ("A") STORE AS SECUREFILE (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192
CACHE NOLOGGING COMPRESS LOW KEEP_DUPLICATES
STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT
))
(10g)
[email protected] > select dbms_metadata.get_ddl('TABLE','T1','SAM') from dual;
DBMS_METADATA.GET_DDL('TABLE','T1','SAM')
--------------------------------------------------------------------------------
CREATE TABLE "SAM"."T1"
("A" CLOB) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
LOB ("A") STORE AS (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 0
CACHE
STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 4 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))
五、总结
此次测试的结论是可以使用EXPDP/IMPDP数据泵实现高-低,低-高版本的迁移,注意高-低过程中使用到version parameter ,开始本想着测试一下EXPDP/IMPDP跨版本的实验,使用到version参数,后来读到官方文档发现限制里还有些内容未能够搞得很清楚,但是也学习到11g new feature。
上一篇: 详细学习Java Cookie技术(用户登录、浏览、访问权限)
下一篇: Mybatis全面分页插件