Oracle11g使用数据泵的network_link方式迁移数据时,不迁移db_link的解决方法
Jan312018
BI的数据库又挂了,服务器主板坏了,远程管理卡坏了、监控卡坏了、并且还坏了4块硬盘。导致操作系统上直接看不到数据库使用的磁盘分区,数据库直接就挂了。
而这时候,同事去机房发现磁盘没有故障,服务器没有报警,只是远程管理卡访问不了了,负责硬件的同事咨询DELL的售后,按照DELL售后说的重启服务器后,操作系统无法启动,4快硬盘亮了黄灯。
DELL的工程师上门检查后,确定是主板坏了,监控卡坏了,硬盘损坏不报警,硬件的同事不知道磁盘损坏,一直到已经坏了4快硬盘,彻底无法使用了才发现故障。
DELL的工程师帮助下,成功启动了操作系统,而且数据文件并没有损坏,貌似是两块热备盘起了作用,但这时硬盘并没有更换,已经不敢对磁盘进行大量的I/O操作了,这时候还是很危险的。
BI的数据库,数据文件一共3.4TB,经查询真实有效的数据只有1TB多一点,所以在尽量减少I/O操作的情况下,使用expdp的network_link的方式迁移数据,把数据直接通过db_link直接迁移到另一个备用的数据库中。
impdp system/oracle1 schemas=ODS network_link=DATA_TO_IVL EXCLUDE=index PARALLEL=4 logfile=ods.log
但是这种方式DB_LINK是不会迁移的,在导入数据时,发现因为缺少DB_LINK导致有很多包和存储过程编译报错。
ALTER PROCEDURE "DW"."P_GET_PGM_INV" COMPILE PLSQL_OPTIMIZE_LEVEL= 2 PLSQL_CODE_TYPE= INTERPRETED PLSQL_DEBUG= TRUE PLSCOPE_SETTINGS= 'IDENTIFIERS:NONE' REUSE SETTINGS TIMESTAMP '2018-01-27 21:12:16' ORA-39082: Object type ALTER_PROCEDURE:"DW"."P_ZZG_TEST" created with compilation warnings ORA-39082: Object type ALTER_PROCEDURE:"DW"."P_UPDATE_BIZ_UNT_CD_1" created with compilation warnings ORA-39082: Object type ALTER_PROCEDURE:"DW"."P_UPDATE_BIZ_UNT_CD_2" created with compilation warnings ORA-39082: Object type ALTER_PROCEDURE:"DW"."P_ZZG_TEST_CUSTOMER" created with compilation warnings ORA-39082: Object type ALTER_PROCEDURE:"DW"."P_ZZG_TEST_CUSTOMER1" created with compilation warnings ORA-39083: Object type ALTER_PROCEDURE failed to create with error: ORA-04052: error occurred when looking up remote object CHGSHS.PLAN_RATE_WEEK_DETAIL@IVALUE ORA-00604: error occurred at recursive SQL level 3 ORA-02019: connection description for remote database not found Failing sql is:
经过查询,发现故障数据库中一共有20个DB_LINK,而新的数据库中只有使用NETWORK_LINK时创建的一个DB_LINK,而且手动创建出这些DB_LINK是可以的,但是我并不知道那些DB_LINK指向的数据库的用户密码,只能去故障数据库把DB_LINK导出来,再到新数据库导入,这样就不需要密码了。
因为只需要导出DB_LINK就可以,这里使用了INCLUDE选项。
[oracle@HUIMAIBI dpdump]$ expdp system/oracle1 dumpfile=dblink.dmp directory=DATA_PUMP_DIR full=Y include=db_link Export: Release 11.2.0.4.0 - Production on Sun Jan 28 04:47:23 2018 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. ;;; 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_FULL_01": system/******** dumpfile=dblink.dmp directory=DATA_PUMP_DIR full=Y include=db_link Estimate in progress using BLOCKS method... Total estimation using BLOCKS method: 0 KB Processing object type DATABASE_EXPORT/SCHEMA/DB_LINK Master table "SYSTEM"."SYS_EXPORT_FULL_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYSTEM.SYS_EXPORT_FULL_01 is: /u01/app/oracle/admin/huimaibi/dpdump/dblink.dmp Job "SYSTEM"."SYS_EXPORT_FULL_01" successfully completed at Sun Jan 28 04:47:42 2018 elapsed 0 00:00:17
新的数据库导入就会把DB_LINK直接导入了。
[oracle@SL010A-IVDB01 u01]$ impdp system/oracle1 directory=expbk dumpfile=dblink.dmp Import: Release 11.2.0.4.0 - Production on Sun Jan 28 04:49:48 2018 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. 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 Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** directory=expbk dumpfile=dblink.dmp Processing object type DATABASE_EXPORT/SCHEMA/DB_LINK ORA-31684: Object type DB_LINK:"DW"."CX" already exists Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Sun Jan 28 04:49:53 2018 elapsed 0 00:00:03
导入完成后,去编译一下失效对象就可以了。