需要把生产环境的某张表,使用expdp导出,然后使用impdp倒进本地测试环境的另一个用户下,在导入的时候报错ORA-39166:
下面具体操作过程:
首先在源端expdp出来,这里我们按着时间条件导出来的,并且由于我的测试环境是11.2.0.1.0,但是源端11.2.0.4.0,目标端版本底,所以需要使用参数version。
[oracle@oracle3 ~]$ expdp liuwenhe/liuwenhe directory=DATA_MIG_DIR tables=INFOSERVICE.t_publish_info dumpfile=t_publish_info09.dmp query=\"where publish_date\>\=to_date\(\'2016-09-01\',\'yyyy-mm-dd\'\) and publish_date\
然后通过sftp传到跳板机
[liuwenhe@S220 ~]$ sftp root@192.168.0.214
Connecting to 192.168.0.214...
Address 192.168.0.214 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.0.214's password:
sftp>
sftp> cd /home/oracle/dp_dir
sftp> ls
mig_parallel_53.dmp nohup.out
t_publish_info09.dmp t_publish_zbxx09.dmp.gz t_publish_zbxx_2015.dmp.gz tpz_20142015_01.dmp.gz tpz_20142015_02.dmp user_regist_ls_fail.dmp x
sftp> get t_publish_zbxx09.dmp
之后通过securefx 传到本地。
执行导入操作,发现报错,具体如下,
C:\Users\manet>impdp liuwenhe/liuwenhe@140 directory=backup dumpfile=t_publish_info09.dmp remap_schema=infoservice:liuwenhe remap_tablespace=infoservice:LIU_TBS tables=INFOSERVICE.t_publish_info;
Import: Release 11.2.0.1.0 - Production on 星期一 10月 10 16:11:50 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39002: 操作无效
ORA-39166: 找不到对象 INFOSERVICE.T_PUBLISH_INFO;。
看到这个报错,我仔细检查了directory的权限,以及dump文件和liuwenhe用户的权限存在否,都没问题,之后怀疑是网络传输导致丢包,于是重新down了一份,传输到本地,执行。依旧报同样的错。在mos上查询之后,有提示说:
如果impdp使用remap_schema,导入dmp的所有数据时则不需要指定tables参数。
然而这里我确实是想把所有的数据都导进去,是不是不用tables这个参数啊,于是我修改impdp导入语句,
C:\Users\manet>impdp liuwenhe/liuwenhe@140 directory=backup dumpfile=t_publish_info09.dmp remap_schema=infoservice:liuwenhe remap_tablespace=infoservice:LIU_TBS
真的成功了。。。。
下面是网上的一篇文章。
需求:把生产上以某些字母开头的表导入到测试环境的其它用户中。
实现方法:
1.在生产环境使用expdp的模糊导出功能,先导出这些表。
2.在测试使用impdp的remap_schema功能将这些表导入到测试环境的其它用户。
实现过程:
1.expdp导出表
$ expdp scott/tiger DIRECTORY=DPUMPDIR DUMPFILE=scott220.DMP tables=prod% JOB_NAME=MYJOB3 LOGFILE=scottEXP.LOG
2.impdp导入表
$ impdp username/password directory=DPUMPDIR dumpfile=scott220.DMP tables=prod_201203_26 remap_schema=scott:liangweilogfile=impdp.log
Import: Release 11.2.0.3.0 - Production on Mon Nov 12 11:32:47 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
ORA-39002: invalid operation
ORA-39166: Object liangwei.prod_201203_26 was not found.
导入过程中,只导入指定表出现ORA-39002,ORA-39166错误。
如果impdp使用remap_schema,且指定要导入的表时,要指定表的schema (也就是需要使用tables这个参数)。
$ impdp username/password directory=DPUMPDIR dumpfile=scott220.DMP tables=scott.prod_201203_26 remap_schema=scott:liangwei logfile=impdp.log
如果impdp使用remap_schema,导入dmp的所有数据时则不需要指定tables参数。
$ impdp username/password directory=DPUMPDIR dumpfile=scott220.DMP remap_schema=scott:liangwei logfile=impdp.log
总结:m如果你从源端down下来了好多个表或者down下来了某个用户(包含多个表),此时你只想impdp其中的一部分表,并且需要导入进另一个用户,也就是需要使用remap_schema参数,这个时候你需要使用tables参数指定你需要导入的表,如果你要导入dump文件的所有的数据,这个时候你不能使用tables参数,否则报错ORA-39166;