阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Oracle使用数据泵 (expdp/impdp)实施迁移

123次阅读
没有评论

共计 37686 个字符,预计需要花费 95 分钟才能阅读完成。

实验环境:

1、导出环境:RedHat6.4+Oracle 11.2.0.4.0,利用数据库自带的 scott 示例用户进行试验测试。

Directory:wjq  à /tmp/seiang_wjq

Oracle 使用数据泵 (expdp/impdp)实施迁移

2、导入环境:CentOS7.1+Oracle 12.2.0.1.0   Oracle12c 默认没有 scott 用户

Directory:imp_wjq  à /tmp/imp_comsys

Oracle 使用数据泵 (expdp/impdp)实施迁移

一、导出数据:

特别注意:如果后续要导入的数据库版本低,所有导出命令就需要在后面加一个 version= 指定版本。例如 11g -> 10g,假设 10g 具体版本为 10.2.0.1,那么就加一个版本的参数 version=10.2.0.1。

1. 首先需要创建 Directory

Oracle 使用数据泵 (expdp/impdp)实施迁移

注意:目录在系统上需要真实存在(mkdir /tmp/seiang_wjq),且有访问的权限。

Oracle 使用数据泵 (expdp/impdp)实施迁移

2. 使用 expdp 导出用户数据

2.1 只导出 scott 用户的元数据,且不包含统计信息;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott content=metadata_onlyexclude=statistics dumpfile=scott_meta.dmp logfile=scott_meta.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:17:16 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scott content=metadata_only exclude=statistics dumpfile=scott_meta.dmp logfile=scott_meta.log

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

/tmp/seiang_wjq/scott_meta.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully completed at Mon Apr 24 14:17:48 2017 elapsed 0 00:00:21

2.2 只导出 scott 用户的数据;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott content=data_only dumpfile=scott_data.dmp logfile=scott_data.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:22:36 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scott content=data_only dumpfile=scott_data.dmp logfile=scott_data.log

Estimate in progress using BLOCKS method…

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 192 KB

. . exported “SCOTT”.”DEPT”                              5.929 KB       4 rows

. . exported “SCOTT”.”EMP”                               8.562 KB      14 rows

. . exported “SCOTT”.”SALGRADE”                          5.859 KB       5 rows

. . exported “SCOTT”.”BONUS”                                 0 KB       0 rows

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

/tmp/seiang_wjq/scott_data.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully completed at Mon Apr 24 14:22:47 2017 elapsed 0 00:00:06

2.3 只导出 scott 用户下的 emp,dept 表及数据;

[oracle@seiangwjq ~]$ expdp scott directory=wjq tables=emp,dept dumpfile=scott_emp_dept.dmp logfile=scott_emp_dept.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:25:37 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

ORA-39002: invalid operation

ORA-39070: Unable to open the log file.

ORA-39087: directory name WJQ is invalid

这里如果用 scott 用户导出,需要注意 scott 用户对于 directory 的权限问题:需要 dba 用户赋予 scott 用户 read,write 目录的权限。

Oracle 使用数据泵 (expdp/impdp)实施迁移

[oracle@seiangwjq ~]$ expdp scott directory=wjq tables=emp,dept dumpfile=scott_emp_dept.dmplogfile=scott_emp_dept.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:28:18 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SCOTT”.”SYS_EXPORT_TABLE_01″:  scott/******** directory=wjq tables=emp,deptdumpfile=scott_emp_dept.dmp logfile=scott_emp_dept.log

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/CONSTRAINT/REF_CONSTRAINT

. . exported “SCOTT”.”DEPT”                              5.929 KB      4 rows

. . exported “SCOTT”.”EMP”                              8.562 KB      14 rows

Master table “SCOTT”.”SYS_EXPORT_TABLE_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:

  /tmp/seiang_wjq/scott_emp_dept.dmp

Job “SCOTT”.”SYS_EXPORT_TABLE_01″ successfullycompleted at Mon Apr 24 14:28:35 2017 elapsed 0 00:00:09

2.4 只导出 scott 用户下的 emp,dept 表结构;

[oracle@seiangwjq ~]$ expdp scott directory=wjq tables=emp,dept content=metadata_onlydumpfile=scott_emp_dept_meta.dmp logfile=scott_emp_dept_meta.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:34:07 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SCOTT”.”SYS_EXPORT_TABLE_01″:  scott/******** directory=wjq tables=emp,deptcontent=metadata_only dumpfile=scott_emp_dept_meta.dmplogfile=scott_emp_dept_meta.log

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/CONSTRAINT/REF_CONSTRAINT

Master table “SCOTT”.”SYS_EXPORT_TABLE_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:

  /tmp/seiang_wjq/scott_emp_dept_meta.dmp

Job “SCOTT”.”SYS_EXPORT_TABLE_01″ successfullycompleted at Mon Apr 24 14:34:21 2017 elapsed 0 00:00:08

2.5 导出 scott 用户下所有的内容;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott dumpfile=scott_all.dmplogfile=scott_all.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:38:10 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scottdumpfile=scott_all.dmp logfile=scott_all.log

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/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

. . exported “SCOTT”.”DEPT”                             5.929 KB      4 rows

. . exported “SCOTT”.”EMP”                              8.562 KB      14 rows

. . exported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . exported “SCOTT”.”BONUS”                                0 KB      0 rows

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

  /tmp/seiang_wjq/scott_all.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfullycompleted at Mon Apr 24 14:38:30 2017 elapsed 0 00:00:16

2.6 并行导出 scott 用户下所有的内容;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott dumpfile=scott_all%U.dmplogfile=scott_all.log parallel=2 

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:44:04 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scottdumpfile=scott_all%U.dmp logfile=scott_all.log parallel=2

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/USER

. . exported “SCOTT”.”DEPT”                              5.929 KB      4 rows

. . exported “SCOTT”.”EMP”                               8.562 KB      14 rows

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

. . exported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . exported “SCOTT”.”BONUS”                                 0 KB      0 rows

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

  /tmp/seiang_wjq/scott_all01.dmp

  /tmp/seiang_wjq/scott_all02.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfullycompleted at Mon Apr 24 14:44:27 2017 elapsed 0 00:00:15

3. 查询当前用户用到的表空间

Oracle 使用数据泵 (expdp/impdp)实施迁移

二、导入数据

导入准备:将刚才从 11g 数据库导出的内容通过 scp 发送给 12c

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

1. 首先需要创建 Directory

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

2. 使用 impdp 导入用户数据

2.1 导入 scott 用户的元数据,且不包含统计信息;

[oracle@seiang ~]$ impdp system directory=imp_wjq dumpfile=scott_meta.dmplogfile=imp_scott_meta.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:26:30 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0- 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_FULL_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_FULL_01″:  system/******** directory=imp_wjqdumpfile=scott_meta.dmp logfile=imp_scott_meta.log

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

Job “SYSTEM”.”SYS_IMPORT_FULL_01″ successfullycompleted at Mon Apr 24 15:27:15 2017 elapsed 0 00:00:20

2.2 导入 scott 用户的数据;

只有在 2.1 导入元数据后才可以导入数据。

[oracle@seiang ~]$ impdp system directory=imp_wjq dumpfile=scott_data.dmplogfile=imp_scott_data.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:29:27 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_FULL_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_FULL_01″:  system/******** directory=imp_wjqdumpfile=scott_data.dmp logfile=imp_scott_data.log

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

. . imported “SCOTT”.”DEPT”                              5.929 KB      4 rows

. . imported “SCOTT”.”EMP”                              8.562 KB      14 rows

. . imported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . imported “SCOTT”.”BONUS”                                0 KB      0 rows

Job “SYSTEM”.”SYS_IMPORT_FULL_01″ successfullycompleted at Mon Apr 24 15:29:44 2017 elapsed 0 00:00:12

2.3 只导入 scott 用户下的 emp 表及数据;

[oracle@seiang ~]$ impdp scott directory=imp_wjq tables=empdumpfile=scott_emp_dept.dmp logfile=imp_scott_emp.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:40:56 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

ORA-39002:invalid operation

ORA-39070:Unable to open the log file.

ORA-39087:directory name IMP_WJQ is invalid

 

因为在导入的时候没有给 imp_wjq 目录赋予 read 和 write 的权限,所以会出现上面的错误,下面就给 imp_wjq 目录授权:

 

Oracle 使用数据泵 (expdp/impdp)实施迁移

[oracle@seiang ~]$ impdp scott directory=imp_wjq tables=emp dumpfile=scott_emp_dept.dmplogfile=imp_scott_emp.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:45:03 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0- 64bit Production

Master table “SCOTT”.”SYS_IMPORT_TABLE_01″successfully loaded/unloaded

Starting “SCOTT”.”SYS_IMPORT_TABLE_01″:  scott/******** directory=imp_wjq tables=empdumpfile=scott_emp_dept.dmp logfile=imp_scott_emp.log

Processing object type TABLE_EXPORT/TABLE/TABLE

ORA-39151:Table “SCOTT”.”EMP” exists. All dependent metadata and datawill be skipped due to table_exists_action of skip

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Job “SCOTT”.”SYS_IMPORT_TABLE_01″ completed with1 error(s) at Mon Apr 24 15:45:13 2017 elapsed 0 00:00:04

2.4 只导入 scott 用户下的 emp,dept 表结构;

由于之前 2.12.22.3 导入的执行,所有的表都已成功导入,为了接下来的实验,我们把 scott 用户下存在的表都删掉;

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

[oracle@seiang ~]$ impdp scott directory=imp_wjq tables=emp,dept dumpfile=scott_emp_dept_meta.dmplogfile=imp_scott_emp_dept_meta.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:59:16 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SCOTT”.”SYS_IMPORT_TABLE_01″successfully loaded/unloaded

Starting “SCOTT”.”SYS_IMPORT_TABLE_01″:  scott/******** directory=imp_wjqtables=emp,dept dumpfile=scott_emp_dept_meta.dmplogfile=imp_scott_emp_dept_meta.log

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/CONSTRAINT/REF_CONSTRAINT

Job “SCOTT”.”SYS_IMPORT_TABLE_01″ successfullycompleted at Mon Apr 24 15:59:22 2017 elapsed 0 00:00:02

由于导出就是 emp,dept 两张表,所以也可以不指定 tables,以下两种写法在这里都是可以的:

[oracle@seiang ~]$ impdp scott directory=imp_wjqdumpfile=scott_emp_dept_meta.dmp logfile=imp_scott_emp_dept_meta.log

或者

[oracle@seiang ~]$ impdp scott directory=imp_wjqdumpfile=scott_emp_dept_meta.dmp logfile=imp_scott_emp_dept_meta.log full=y

 

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2017-05/143878p2.htm

 

2.5 导入 scott 用户下所有的内容;

如果是在 2.4 基础上直接导入,会因为 emp,dept 表已经存在导致导入过程中会由于 table_exists_action 参数的默认选项是 skip,从而跳过 emp,dept 表数据的导入,如下:

[Oracle@seiang ~]$ impdp system directory=imp_wjq schemas=scottdumpfile=scott_all.dmp logfile=imp_scott_all.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 16:06:28 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_SCHEMA_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_SCHEMA_01″:  system/******** directory=imp_wjqschemas=scott dumpfile=scott_all.dmp logfile=imp_scott_all.log

Processing object type SCHEMA_EXPORT/USER

ORA-31684:Object type USER:”SCOTT” already exists

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

ORA-39151:Table “SCOTT”.”EMP” exists. All dependent metadata and datawill be skipped due to table_exists_action of skip

ORA-39151:Table “SCOTT”.”DEPT” exists. All dependent metadata anddata will be skipped due to table_exists_action of skip

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

. . imported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . imported “SCOTT”.”BONUS”                                0 KB      0 rows

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Job “SYSTEM”.”SYS_IMPORT_SCHEMA_01″ completedwith 3 error(s) at Mon Apr 24 16:06:38 2017 elapsed 0 00:00:05

所以这时我们想导入这些数据,可以加参数 table_exists_action,指定想要的选项。
TABLE_EXISTS_ACTION
Action to take if imported object already exists.
Valid keywords are:
APPEND, REPLACE,[SKIP] and TRUNCATE.

这里选择 truncate,即如果表存在,那么处理方式是 truncate 此表后导入文件中包含的数据。

[oracle@seiang ~]$ impdp system directory=imp_wjq schemas=scott table_exists_action=truncatedumpfile=scott_all.dmp logfile=imp_scott_all.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 16:17:44 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_SCHEMA_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_SCHEMA_01″:  system/******** directory=imp_wjqschemas=scott table_exists_action=truncate dumpfile=scott_all.dmplogfile=imp_scott_all.log

Processing object type SCHEMA_EXPORT/USER

ORA-31684: Object type USER:”SCOTT” already exists

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

ORA-39120:Table “SCOTT”.”DEPT” can’t be truncated, data will beskipped. Failing error is:

ORA-02266:unique/primary keys in table referenced by enabled foreign keys

ORA-00955:name is already used by an existing object

Table”SCOTT”.”SALGRADE” exists and has been truncated. Data will be loaded but all dependent metadata will be skipped dueto table_exists_action of truncate

Table”SCOTT”.”BONUS” exists and has been truncated. Data will be loaded but all dependent metadata will be skipped dueto table_exists_action of truncate

Table”SCOTT”.”EMP” exists and has been truncated. Data will be loaded but all dependent metadata will be skipped dueto table_exists_action of truncate

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

ORA-31693: Table data object “SCOTT”.”EMP”failed to load/unload and is being skipped due to error:

ORA-02291: integrity constraint (SCOTT.FK_DEPTNO) violated – parentkey not found

. . imported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . imported “SCOTT”.”BONUS”                                0 KB      0 rows

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

ORA-39112: Dependent object typeINDEX:”SCOTT”.”PK_DEPT” skipped, base object typeTABLE:”SCOTT”.”DEPT” creation failed

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

ORA-39112: Dependent object typeCONSTRAINT:”SCOTT”.”PK_DEPT” skipped, base object typeTABLE:”SCOTT”.”DEPT” creation failed

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Job “SYSTEM”.”SYS_IMPORT_SCHEMA_01″ completedwith 5 error(s) at Mon Apr 24 16:18:00 2017 elapsed 0 00:00:

注意:如果这里选用 append 选项,那么如果原表有数据,且没有合理的约束条件,则可能导致数据的重复导入,所以, 生产环境实际导入过程中一定要弄清楚数据的实际情况才能准确决定如何选用此参数的选项

2.6 并行导入 scott 用户下所有的内容;

Oracle 使用数据泵 (expdp/impdp)实施迁移

[oracle@seiang ~]$ impdp system directory=imp_wjq schemas=scott table_exists_action=replacedumpfile=scott_all%U.dmplogfile=imp_scott_all_U.log parallel=2

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 16:26:42 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_SCHEMA_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_SCHEMA_01″:  system/******** directory=imp_wjqschemas=scott table_exists_action=replace dumpfile=scott_all%U.dmplogfile=imp_scott_all_U.log parallel=2

Processing object type SCHEMA_EXPORT/USER

ORA-31684:Object type USER:”SCOTT” already exists

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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 “SCOTT”.”DEPT”                              5.929 KB      4 rows

. . imported “SCOTT”.”EMP”                              8.562 KB      14 rows

. . imported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . imported “SCOTT”.”BONUS”                                0 KB      0 rows

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Job “SYSTEM”.”SYS_IMPORT_SCHEMA_01″ completedwith 1 error(s) at Mon Apr 24 16:26:52 2017 elapsed 0 00:00:06

3. 特殊需求

特殊需求环境准备:
1)创建表空间user2
SYS@ORCL>create tablespace user2 datafile ''/u01/app/oracle/oradata/orcl/user02.dbf'size 20M autoextend on maxsize 5G;
2)创建用户scott2
SYS@ORCL>create user scott2 identified by tiger defaulttablespace user2;
3)赋权用户scott2
SYS@ORCL>grant connect, resource to scott2;

Oracle 使用数据泵 (expdp/impdp)实施迁移

3.1 如果导入环境的用户不同;

需求:将原 scott 用户的数据导入到现在的 scott2 用户。

[oracle@seiang orcl]$ impdp system directory=imp_wjq schemas=scott remap_schema=scott:scott2table_exists_action=replacedumpfile=scott_all%U.dmp logfile=imp_scott2_all.log parallel=2

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 16:46:13 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_SCHEMA_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_SCHEMA_01″:  system/******** directory=imp_wjqschemas=scott remap_schema=scott:scott2 table_exists_action=replacedumpfile=scott_all%U.dmp logfile=imp_scott2_all.log parallel=2

Processing object type SCHEMA_EXPORT/USER

ORA-31684: Object type USER:”SCOTT2″ already exists

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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 “SCOTT2″.”DEPT”                            5.929 KB      4 rows

. . imported “SCOTT2″.”EMP”                              8.562 KB      14 rows

. . imported “SCOTT2″.”SALGRADE”                        5.859 KB      5 rows

. . imported “SCOTT2″.”BONUS”                                0 KB      0 rows

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Job “SYSTEM”.”SYS_IMPORT_SCHEMA_01″ completedwith 1 error(s) at Mon Apr 24 16:46:24 2017 elapsed 0 00:00:06

3.2 如果导入环境的表空间也不同;

需求:将原 users 表空间的对象重定向到 users2 表空间。

[oracle@seiang orcl]$ impdp system directory=imp_wjq schemas=scottremap_schema=scott:scott2 remap_tablespace=users:user2table_exists_action=replace dumpfile=scott_all%U.dmp logfile=imp_scott2_all.logparallel=2

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 16:47:59 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_SCHEMA_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_SCHEMA_01″:  system/******** directory=imp_wjqschemas=scott remap_schema=scott:scott2 remap_tablespace=users:user2table_exists_action=replace dumpfile=scott_all%U.dmp logfile=imp_scott2_all.logparallel=2

Processing object type SCHEMA_EXPORT/USER

ORA-31684: Object type USER:”SCOTT2″ already exists

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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 “SCOTT2″.”DEPT”                            5.929 KB      4 rows

. . imported “SCOTT2″.”EMP”                              8.562 KB      14 rows

. . imported “SCOTT2″.”SALGRADE”                        5.859 KB      5 rows

. . imported “SCOTT2″.”BONUS”                                0 KB      0 rows

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Job “SYSTEM”.”SYS_IMPORT_SCHEMA_01″ completedwith 1 error(s) at Mon Apr 24 16:48:10 2017 elapsed 0 00:00:06

根据结果,可以发现导入的日志最后都提示有一个错误,往上查发现是报错 ORA-31684 用户已存在,这是因为我们习惯在导入前建立好对应的用户,避免一些其他的权限错误,所以这个错误是可以忽略的。当然其实如果我们已经建立了对应的表空间,用户也是可以不事先建立的,在导入的时候,如果用户不存在,会自动创建用户;

更多 Oracle 相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-05/143878.htm

实验环境:

1、导出环境:RedHat6.4+Oracle 11.2.0.4.0,利用数据库自带的 scott 示例用户进行试验测试。

Directory:wjq  à /tmp/seiang_wjq

Oracle 使用数据泵 (expdp/impdp)实施迁移

2、导入环境:CentOS7.1+Oracle 12.2.0.1.0   Oracle12c 默认没有 scott 用户

Directory:imp_wjq  à /tmp/imp_comsys

Oracle 使用数据泵 (expdp/impdp)实施迁移

一、导出数据:

特别注意:如果后续要导入的数据库版本低,所有导出命令就需要在后面加一个 version= 指定版本。例如 11g -> 10g,假设 10g 具体版本为 10.2.0.1,那么就加一个版本的参数 version=10.2.0.1。

1. 首先需要创建 Directory

Oracle 使用数据泵 (expdp/impdp)实施迁移

注意:目录在系统上需要真实存在(mkdir /tmp/seiang_wjq),且有访问的权限。

Oracle 使用数据泵 (expdp/impdp)实施迁移

2. 使用 expdp 导出用户数据

2.1 只导出 scott 用户的元数据,且不包含统计信息;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott content=metadata_onlyexclude=statistics dumpfile=scott_meta.dmp logfile=scott_meta.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:17:16 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scott content=metadata_only exclude=statistics dumpfile=scott_meta.dmp logfile=scott_meta.log

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

/tmp/seiang_wjq/scott_meta.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully completed at Mon Apr 24 14:17:48 2017 elapsed 0 00:00:21

2.2 只导出 scott 用户的数据;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott content=data_only dumpfile=scott_data.dmp logfile=scott_data.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:22:36 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scott content=data_only dumpfile=scott_data.dmp logfile=scott_data.log

Estimate in progress using BLOCKS method…

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 192 KB

. . exported “SCOTT”.”DEPT”                              5.929 KB       4 rows

. . exported “SCOTT”.”EMP”                               8.562 KB      14 rows

. . exported “SCOTT”.”SALGRADE”                          5.859 KB       5 rows

. . exported “SCOTT”.”BONUS”                                 0 KB       0 rows

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

/tmp/seiang_wjq/scott_data.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfully completed at Mon Apr 24 14:22:47 2017 elapsed 0 00:00:06

2.3 只导出 scott 用户下的 emp,dept 表及数据;

[oracle@seiangwjq ~]$ expdp scott directory=wjq tables=emp,dept dumpfile=scott_emp_dept.dmp logfile=scott_emp_dept.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:25:37 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

ORA-39002: invalid operation

ORA-39070: Unable to open the log file.

ORA-39087: directory name WJQ is invalid

这里如果用 scott 用户导出,需要注意 scott 用户对于 directory 的权限问题:需要 dba 用户赋予 scott 用户 read,write 目录的权限。

Oracle 使用数据泵 (expdp/impdp)实施迁移

[oracle@seiangwjq ~]$ expdp scott directory=wjq tables=emp,dept dumpfile=scott_emp_dept.dmplogfile=scott_emp_dept.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:28:18 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SCOTT”.”SYS_EXPORT_TABLE_01″:  scott/******** directory=wjq tables=emp,deptdumpfile=scott_emp_dept.dmp logfile=scott_emp_dept.log

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/CONSTRAINT/REF_CONSTRAINT

. . exported “SCOTT”.”DEPT”                              5.929 KB      4 rows

. . exported “SCOTT”.”EMP”                              8.562 KB      14 rows

Master table “SCOTT”.”SYS_EXPORT_TABLE_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:

  /tmp/seiang_wjq/scott_emp_dept.dmp

Job “SCOTT”.”SYS_EXPORT_TABLE_01″ successfullycompleted at Mon Apr 24 14:28:35 2017 elapsed 0 00:00:09

2.4 只导出 scott 用户下的 emp,dept 表结构;

[oracle@seiangwjq ~]$ expdp scott directory=wjq tables=emp,dept content=metadata_onlydumpfile=scott_emp_dept_meta.dmp logfile=scott_emp_dept_meta.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:34:07 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SCOTT”.”SYS_EXPORT_TABLE_01″:  scott/******** directory=wjq tables=emp,deptcontent=metadata_only dumpfile=scott_emp_dept_meta.dmplogfile=scott_emp_dept_meta.log

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/CONSTRAINT/REF_CONSTRAINT

Master table “SCOTT”.”SYS_EXPORT_TABLE_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:

  /tmp/seiang_wjq/scott_emp_dept_meta.dmp

Job “SCOTT”.”SYS_EXPORT_TABLE_01″ successfullycompleted at Mon Apr 24 14:34:21 2017 elapsed 0 00:00:08

2.5 导出 scott 用户下所有的内容;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott dumpfile=scott_all.dmplogfile=scott_all.log

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:38:10 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scottdumpfile=scott_all.dmp logfile=scott_all.log

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/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

. . exported “SCOTT”.”DEPT”                             5.929 KB      4 rows

. . exported “SCOTT”.”EMP”                              8.562 KB      14 rows

. . exported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . exported “SCOTT”.”BONUS”                                0 KB      0 rows

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

  /tmp/seiang_wjq/scott_all.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfullycompleted at Mon Apr 24 14:38:30 2017 elapsed 0 00:00:16

2.6 并行导出 scott 用户下所有的内容;

[oracle@seiangwjq ~]$ expdp system directory=wjq schemas=scott dumpfile=scott_all%U.dmplogfile=scott_all.log parallel=2 

Export: Release 11.2.0.4.0 – Production on Mon Apr 24 14:44:04 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options

Starting “SYSTEM”.”SYS_EXPORT_SCHEMA_01″:  system/******** directory=wjq schemas=scottdumpfile=scott_all%U.dmp logfile=scott_all.log parallel=2

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/USER

. . exported “SCOTT”.”DEPT”                              5.929 KB      4 rows

. . exported “SCOTT”.”EMP”                               8.562 KB      14 rows

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

. . exported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . exported “SCOTT”.”BONUS”                                 0 KB      0 rows

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

Master table “SYSTEM”.”SYS_EXPORT_SCHEMA_01″successfully loaded/unloaded

******************************************************************************

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

  /tmp/seiang_wjq/scott_all01.dmp

  /tmp/seiang_wjq/scott_all02.dmp

Job “SYSTEM”.”SYS_EXPORT_SCHEMA_01″ successfullycompleted at Mon Apr 24 14:44:27 2017 elapsed 0 00:00:15

3. 查询当前用户用到的表空间

Oracle 使用数据泵 (expdp/impdp)实施迁移

二、导入数据

导入准备:将刚才从 11g 数据库导出的内容通过 scp 发送给 12c

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

1. 首先需要创建 Directory

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

2. 使用 impdp 导入用户数据

2.1 导入 scott 用户的元数据,且不包含统计信息;

[oracle@seiang ~]$ impdp system directory=imp_wjq dumpfile=scott_meta.dmplogfile=imp_scott_meta.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:26:30 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0- 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_FULL_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_FULL_01″:  system/******** directory=imp_wjqdumpfile=scott_meta.dmp logfile=imp_scott_meta.log

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

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/CONSTRAINT/REF_CONSTRAINT

Job “SYSTEM”.”SYS_IMPORT_FULL_01″ successfullycompleted at Mon Apr 24 15:27:15 2017 elapsed 0 00:00:20

2.2 导入 scott 用户的数据;

只有在 2.1 导入元数据后才可以导入数据。

[oracle@seiang ~]$ impdp system directory=imp_wjq dumpfile=scott_data.dmplogfile=imp_scott_data.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:29:27 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SYSTEM”.”SYS_IMPORT_FULL_01″successfully loaded/unloaded

Starting “SYSTEM”.”SYS_IMPORT_FULL_01″:  system/******** directory=imp_wjqdumpfile=scott_data.dmp logfile=imp_scott_data.log

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

. . imported “SCOTT”.”DEPT”                              5.929 KB      4 rows

. . imported “SCOTT”.”EMP”                              8.562 KB      14 rows

. . imported “SCOTT”.”SALGRADE”                          5.859 KB      5 rows

. . imported “SCOTT”.”BONUS”                                0 KB      0 rows

Job “SYSTEM”.”SYS_IMPORT_FULL_01″ successfullycompleted at Mon Apr 24 15:29:44 2017 elapsed 0 00:00:12

2.3 只导入 scott 用户下的 emp 表及数据;

[oracle@seiang ~]$ impdp scott directory=imp_wjq tables=empdumpfile=scott_emp_dept.dmp logfile=imp_scott_emp.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:40:56 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

ORA-39002:invalid operation

ORA-39070:Unable to open the log file.

ORA-39087:directory name IMP_WJQ is invalid

 

因为在导入的时候没有给 imp_wjq 目录赋予 read 和 write 的权限,所以会出现上面的错误,下面就给 imp_wjq 目录授权:

 

Oracle 使用数据泵 (expdp/impdp)实施迁移

[oracle@seiang ~]$ impdp scott directory=imp_wjq tables=emp dumpfile=scott_emp_dept.dmplogfile=imp_scott_emp.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:45:03 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0- 64bit Production

Master table “SCOTT”.”SYS_IMPORT_TABLE_01″successfully loaded/unloaded

Starting “SCOTT”.”SYS_IMPORT_TABLE_01″:  scott/******** directory=imp_wjq tables=empdumpfile=scott_emp_dept.dmp logfile=imp_scott_emp.log

Processing object type TABLE_EXPORT/TABLE/TABLE

ORA-39151:Table “SCOTT”.”EMP” exists. All dependent metadata and datawill be skipped due to table_exists_action of skip

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Job “SCOTT”.”SYS_IMPORT_TABLE_01″ completed with1 error(s) at Mon Apr 24 15:45:13 2017 elapsed 0 00:00:04

2.4 只导入 scott 用户下的 emp,dept 表结构;

由于之前 2.12.22.3 导入的执行,所有的表都已成功导入,为了接下来的实验,我们把 scott 用户下存在的表都删掉;

Oracle 使用数据泵 (expdp/impdp)实施迁移

Oracle 使用数据泵 (expdp/impdp)实施迁移

[oracle@seiang ~]$ impdp scott directory=imp_wjq tables=emp,dept dumpfile=scott_emp_dept_meta.dmplogfile=imp_scott_emp_dept_meta.log

Import: Release 12.2.0.1.0 – Production on Mon Apr 24 15:59:16 2017

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Password:

Connected to: Oracle Database 12c Enterprise Edition Release12.2.0.1.0 – 64bit Production

Master table “SCOTT”.”SYS_IMPORT_TABLE_01″successfully loaded/unloaded

Starting “SCOTT”.”SYS_IMPORT_TABLE_01″:  scott/******** directory=imp_wjqtables=emp,dept dumpfile=scott_emp_dept_meta.dmplogfile=imp_scott_emp_dept_meta.log

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/CONSTRAINT/REF_CONSTRAINT

Job “SCOTT”.”SYS_IMPORT_TABLE_01″ successfullycompleted at Mon Apr 24 15:59:22 2017 elapsed 0 00:00:02

由于导出就是 emp,dept 两张表,所以也可以不指定 tables,以下两种写法在这里都是可以的:

[oracle@seiang ~]$ impdp scott directory=imp_wjqdumpfile=scott_emp_dept_meta.dmp logfile=imp_scott_emp_dept_meta.log

或者

[oracle@seiang ~]$ impdp scott directory=imp_wjqdumpfile=scott_emp_dept_meta.dmp logfile=imp_scott_emp_dept_meta.log full=y

 

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2017-05/143878p2.htm

 

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计37686字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中