欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

一个非常简单的IMPDP事儿

程序员文章站 2022-04-06 17:57:30
EXPDP出来的DMP文件包含2个Schema的表,现在要IMPDP到一个Schema里面试了几把都报错,好久不用逻辑导出入,折腾了好久,出现各种错误1、创建目录并授权create or replace directory DUMPDIR as '/home/oracle/dump_dir';gra ......

EXPDP出来的DMP文件包含2个Schema的表,现在要IMPDP到一个Schema里面
试了几把都报错,好久不用逻辑导出入,折腾了好久,出现各种错误
1、创建目录并授权
create or replace directory DUMPDIR as '/home/oracle/dump_dir';
grant read,write on directory DUMPDIR to test2;
2、ORDER用户的表T_ORDER_DEPOSIT_530 impdp导入TEST2用户下
impdp test2/test123 remap_schema=ORDER:TEST2 tables=ORDER.T_ORDER_DEPOSIT_530 directory=DUMPDIR dumpfile=OA188672.dmp logfile=OA188672.log
----------------------------------------------------------------------------------------
err log:
Starting "TEST"."SYS_IMPORT_FULL_01": test/******** parallel=4 remap_schema=TESTUSER:TEST dumpfile=OA186751.dmp logfile=OA186751_imp.log DIRECTORY=DUMPDIR
Processing object type TABLE_EXPORT/TABLE/PROCACT_INSTANCE
ORA-39083: Object type PROCACT_INSTANCE failed to create with error:
ORA-31625: Schema MEMBERS is needed to import this object, but is unaccessible
ORA-01435: user does not exist

Starting "TEST"."SYS_IMPORT_FULL_01": test/******** remap_table=TESTUSER.T_ORDER_518:TEST.T_ORDER_518 dumpfile=OA186751.dmp logfile=OA186751_imp_t_order.log DIRECTORY=DUMPDIR
Processing object type TABLE_EXPORT/TABLE/PROCACT_INSTANCE
ORA-39083: Object type PROCACT_INSTANCE failed to create with error:
ORA-31625: Schema MEMBERS is needed to import this object, but is unaccessible
ORA-01435: user does not exist

Starting "TEST"."SYS_IMPORT_TABLE_01": test/******** TABLES=TESTUSER.T_ORDER_518,TESTUSER.T_ORDER_SETTLE_INFO_518,TESTUSER.T_MERCHANT_SETTLE_518,TESTUSER.T_ORDER_ABNORMAL_518,TESTUSER.T_ORDER_REFUND_518,MEMBERS.T_RECIEVE_PAY_TRADE_6MER0504 dumpfile=OA186751.dmp logfile=OA186751_imp.log DIRECTORY=DUMPDIR
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-39083: Object type TABLE:"MEMBERS"."T_RECIEVE_PAY_TRADE_6MER0504" failed to create with error:
ORA-01918: user 'MEMBERS' does not exist
Failing sql is:

上面涉及两点,1、Schema变了-> remap_schema来转换,2、TABLE要指定Schema
下面将MEMBERS用户下备份的表恢复到TEST2用户下
[oracle@localhost dump_dir]$ impdp test2/test123 remap_schema=MEMBERS:TEST2 tables=MEMBERS.T_RECIEVE_PAY_TRADE_6MER0504 directory=DUMPDIR dumpfile=OA186751.dmp logfile=OA186751_MEMBERS.log

Import: Release 11.2.0.1.0 - Production on Mon May 21 19:33:24 2018

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 "TEST2"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "TEST2"."SYS_IMPORT_TABLE_01": test2/******** remap_schema=MEMBERS:TEST2 tables=MEMBERS.T_RECIEVE_PAY_TRADE_6MER0504 directory=DUMPDIR dumpfile=OA186751.dmp logfile=OA186751_MEMBERS.log
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "TEST2"."T_RECIEVE_PAY_TRADE_6MER0504" 82.31 KB 567 rows
Job "TEST2"."SYS_IMPORT_TABLE_01" successfully completed at 19:33:32

再对另外一个Schema进行IMPDP就可以了。。。

错误例子:
下面这个首先关键字就没选好,只是想把表从一个用户导入到另外一个用户,而remap_table是修改表名称
--impdp test/test123 DIRECTORY=DUMPDIR remap_table=MEMBER.T_RECIEVE_PAY_TRADE_6MER0504:TEST.T_RECIEVE_PAY_TRADE_6MER0504 dumpfile=OA186751.dmp logfile=OA186751_imp.log


参考及示例出处:
https://blog.csdn.net/e_wsq/article/details/78374020
remap_table、remap_tablespace多组对象转换的话,每组对象之间用逗号隔开
tables多张表时,每张表之间用逗号隔开

Remap_tablespace如果需要转换多个表空间,如A1转换成B1,A2转换成B1,有如下两种方式
remap_tablespace=A1:B1 remap_tablespace=A2:B1
remap_tablespace= A1:B1, A2:B1

Remap_table如果需要转换多个表名
同一个schema的情况下,如A1转换成B1,A2转换成B1,有如下两种方式
remap_table=A1:B1 remap_table=A2:B1
remap_table= A1:B1, A2:B1

remap_table、remap_tablespace多组对象转换的话,每组对象之间用逗号隔开
tables多张表时,每张表之间用逗号隔开

Remap_tablespace如果需要转换多个表空间,如A1转换成B1,A2转换成B1,有如下两种方式
remap_tablespace=A1:B1 remap_tablespace=A2:B1
remap_tablespace= A1:B1, A2:B1

Remap_table如果需要转换多个表名
同一个schema的情况下,如A1转换成B1,A2转换成B1,有如下两种方式
remap_table=A1:B1 remap_table=A2:B1
remap_table= A1:B1, A2:B1
跨schema只导出导入表并重命名的标准方式如下
expdp时tables写上schema.表名并用逗号隔开
impdp时需要remap_schema, tables可写可不写,remap_table冒号前面的表名加上schema,冒号后面的表名不加schema
expdp system/123456 tables=t01.test101,t01.test102,t01.test103 directory=DATA_PUMP_DIR dumpfile=t011.dbf
一个案例
A服务器导出用户ESB的一张分区表ESB_LOG
expdp system/123456 directory=DATA_PUMP_DIR dumpfile=ESB_LOG.dmp logfile=ESB_LOG.log tables=ESB.ESB_LOG
导入到B服务器的part用户,表名改为ESB_LOG2(加了tables=ESB.ESB_LOG,其实加不加无所谓,反正ESB_LOG.dm就是只有一张表ESB.ESB_LOG)
impdp system/123456 directory=DATA_PUMP_DIR dumpfile=ESB_LOG.dmp logfile=ESB_LOG2.log tables=ESB.ESB_LOGremap_schema=ESB:part remap_tablespace=ESB07:part,ESB08:part,ESB09:part,ESB10:part,ESB11:part,ESB12:part,ESB:part remap_table=ESB.ESB_LOG:ESB_LOG2