oracle impdp TABLE_EXISTS_ACTION 测试

概述:在做数据库dmp文件导入时有个参数TABLE_EXISTS_ACTION是针对目标库中已经存在相同表时数据将会如何被灌入呢?

实验验证:

TABLE_EXISTS_ACTION
Action to take if imported object already exists.

Valid keywords are: APPEND, REPLACE, [SKIP] and TRUNCATE.

CUBE@@db11g> select * from test;

ID
----------

1

SYS@AS SYSDBA@pdbprod4> select * from cube.test;

        ID
----------
         1

1 row selected.

CUBE@@db11g> insert into test values (2);
1 row created.
CUBE@@db11g> insert into test values (3);
1 row created.
CUBE@@db11g> insert into test values (1);
1 row created.
CUBE@@db11g> commit;
Commit complete.
CUBE@@db11g> select * from test;
ID
----------
1
2
3

1

[oracle@host01 admin]$ impdp \'sys/oracle@host01:1521/PDBPROD4.example.com as sysdba\' directory=xtts  logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=append
Import: Release 12.1.0.2.0 - Production on Tue May 22 16:24:19 2018
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
22-MAY-18 16:24:25.658: Starting "SYS"."SYS_IMPORT_SCHEMA_04":  "sys/********@host01:1521/PDBPROD4.example.com AS SYSDBA" directory=xtts logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=append 
22-MAY-18 16:24:26.779: Estimate in progress using BLOCKS method...
22-MAY-18 16:24:28.488: Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
22-MAY-18 16:24:28.529: Total estimation using BLOCKS method: 64 KB
22-MAY-18 16:24:29.063: Processing object type SCHEMA_EXPORT/USER
22-MAY-18 16:24:29.198: ORA-31684: Object type USER:"CUBE" already exists
22-MAY-18 16:24:29.215: Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
22-MAY-18 16:24:29.281: Processing object type SCHEMA_EXPORT/ROLE_GRANT
22-MAY-18 16:24:29.375: Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
22-MAY-18 16:24:29.759: Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
22-MAY-18 16:24:35.064: Processing object type SCHEMA_EXPORT/TABLE/TABLE
22-MAY-18 16:24:45.424: Table "CUBE"."TEST" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
22-MAY-18 16:24:45.920: . . imported "CUBE"."TEST"                                    4 rows

22-MAY-18 16:24:48.784: Job "SYS"."SYS_IMPORT_SCHEMA_04" completed with 1 error(s) at Tue May 22 16:24:48 2018 elapsed 0 00:00:26

SYS@AS SYSDBA@pdbprod4> select * from cube.test;

        ID
----------
         1
         1
         2
         3
         1

5 rows selected.

CUBE@@db11g> select count(*) from test;

  COUNT(*)
----------

4

-----------------------------------------------------------------------------------------------------

CUBE@@db11g> select * from test;
ID
----------
1
2
1

2

SYS@AS SYSDBA@pdbprod4> select * from cube.test;

        ID
----------
         1

1 row selected.

[oracle@host01 admin]$ impdp \'sys/oracle@host01:1521/PDBPROD4.example.com as sysdba\' directory=xtts  logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=replace


Import: Release 12.1.0.2.0 - Production on Tue May 22 16:31:03 2018


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


Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
22-MAY-18 16:31:10.202: Starting "SYS"."SYS_IMPORT_SCHEMA_04":  "sys/********@host01:1521/PDBPROD4.example.com AS SYSDBA" directory=xtts logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=replace 
22-MAY-18 16:31:11.590: Estimate in progress using BLOCKS method...
22-MAY-18 16:31:13.994: Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
22-MAY-18 16:31:14.017: Total estimation using BLOCKS method: 64 KB
22-MAY-18 16:31:14.749: Processing object type SCHEMA_EXPORT/USER
22-MAY-18 16:31:16.490: ORA-31684: Object type USER:"CUBE" already exists
22-MAY-18 16:31:16.997: Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
22-MAY-18 16:31:17.106: Processing object type SCHEMA_EXPORT/ROLE_GRANT
22-MAY-18 16:31:17.251: Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
22-MAY-18 16:31:17.808: Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
22-MAY-18 16:31:25.798: Processing object type SCHEMA_EXPORT/TABLE/TABLE
22-MAY-18 16:31:29.437: . . imported "CUBE"."TEST"                                    4 rows

22-MAY-18 16:31:32.600: Job "SYS"."SYS_IMPORT_SCHEMA_04" completed with 1 error(s) at Tue May 22 16:31:32 2018 elapsed 0 00:00:26

SYS@AS SYSDBA@pdbprod4> select * from cube.test;

        ID
----------
         1
         2
         1
         2

4 rows selected.

---------------------------------------------------------------------------------

CUBE@@db11g> select * from test;

ID
----------
1
2
3
1

2

SYS@AS SYSDBA@pdbprod4> select * from cube.test;

        ID
----------
         1
         2
         1
         2

4 rows selected.

[oracle@host01 admin]$ impdp \'sys/oracle@host01:1521/PDBPROD4.example.com as sysdba\' directory=xtts  logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=skip


Import: Release 12.1.0.2.0 - Production on Tue May 22 16:34:24 2018


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


Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
22-MAY-18 16:34:29.116: Starting "SYS"."SYS_IMPORT_SCHEMA_04":  "sys/********@host01:1521/PDBPROD4.example.com AS SYSDBA" directory=xtts logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=skip 
22-MAY-18 16:34:30.012: Estimate in progress using BLOCKS method...
22-MAY-18 16:34:31.636: Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
22-MAY-18 16:34:31.682: Total estimation using BLOCKS method: 64 KB
22-MAY-18 16:34:32.220: Processing object type SCHEMA_EXPORT/USER
22-MAY-18 16:34:32.369: ORA-31684: Object type USER:"CUBE" already exists
22-MAY-18 16:34:32.389: Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
22-MAY-18 16:34:32.445: Processing object type SCHEMA_EXPORT/ROLE_GRANT
22-MAY-18 16:34:32.534: Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
22-MAY-18 16:34:32.912: Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
22-MAY-18 16:34:37.885: Processing object type SCHEMA_EXPORT/TABLE/TABLE
22-MAY-18 16:34:39.647: Table "CUBE"."TEST" exists. All dependent metadata and data will be skipped due to table_exists_action of skip

22-MAY-18 16:34:40.472: Job "SYS"."SYS_IMPORT_SCHEMA_04" completed with 1 error(s) at Tue May 22 16:34:40 2018 elapsed 0 00:00:14

------------------------------------------------------------------------------------------

CUBE@@db11g> select * from test;

ID
----------
 1
 2
 3
 1

 2

SYS@AS SYSDBA@pdbprod4> select * from cube.test;

        ID
----------
         1
         2
         1
         2

4 rows selected.

[oracle@host01 admin]$ impdp \'sys/oracle@host01:1521/PDBPROD4.example.com as sysdba\' directory=xtts  logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=TRUNCATE


Import: Release 12.1.0.2.0 - Production on Tue May 22 16:35:37 2018


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


Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
22-MAY-18 16:35:40.497: Starting "SYS"."SYS_IMPORT_SCHEMA_04":  "sys/********@host01:1521/PDBPROD4.example.com AS SYSDBA" directory=xtts logtime=all parallel=4 NETWORK_LINK=DB11g schemas=cube logfile=imp11g.log TABLE_EXISTS_ACTION=TRUNCATE 
22-MAY-18 16:35:41.461: Estimate in progress using BLOCKS method...
22-MAY-18 16:35:43.498: Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
22-MAY-18 16:35:43.565: Total estimation using BLOCKS method: 64 KB
22-MAY-18 16:35:44.132: Processing object type SCHEMA_EXPORT/USER
22-MAY-18 16:35:44.227: ORA-31684: Object type USER:"CUBE" already exists
22-MAY-18 16:35:44.232: Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
22-MAY-18 16:35:44.295: Processing object type SCHEMA_EXPORT/ROLE_GRANT
22-MAY-18 16:35:44.384: Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
22-MAY-18 16:35:44.761: Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
22-MAY-18 16:35:49.528: Processing object type SCHEMA_EXPORT/TABLE/TABLE
22-MAY-18 16:35:56.655: Table "CUBE"."TEST" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
22-MAY-18 16:35:57.034: . . imported "CUBE"."TEST"                                    5 rows
22-MAY-18 16:35:58.514: Job "SYS"."SYS_IMPORT_SCHEMA_04" completed with 1 error(s) at Tue May 22 16:35:58 2018 elapsed 0 00:00:20


总结:impd 导入数据时TABLE_EXISTS_ACTION:

1、append 时,当目标库中没有相同的表名时,将新建相同表并导入数据;当目标数据库中已经存在相关表并已经有数据存在,则将把源库中的数据再后续追加插入(我测试的表是没有约束条件的,如果表有约束请另外测试);

2、replace时,当目标库中没有相同的表名时,将新建相同表并导入数据;当目标数据库中已经存在相关表并已经有数据存在,则将把源库中的表以及数据替换目标的表跟数据;

3、skip时,当目标库中没有相同的表名时,将新建相同表并导入数据;当目标数据库中已经存在相关表并已经有数据存在,则对目标数据库中存在的表将跳过,但对不存在的表仍旧新建相同表并导入数据;

4、TRUNCATE时,当目标库中没有相同的表名时,将新建相同表并导入数据;当目标数据库中已经存在相关表并已经有数据存在,则将把目标库中的数据进行清查后再将源库的数据进行插入,最后的数据应该与replace相同。

具体replace与TRUNCATE的差别可以参考官方手册进行参考:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sutil/datapump-import-utility.html#GUID-C9664F8C-19C5-4177-AC20-5682AEABA07F

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值