一次艰辛的数据导入

一、导出文件

SELECT CURRENT_SCN FROM V$DATABASE;
expdp system/oracle@orcl DIRECTORY=DATA_PUMP_DIR DUMPFILE=FALABELLA_AR_20111214.DMP SCHEMAS=FALABELLA_AR_CORE,FALABELLA_AR_CATA,FALABELLA_AR_CATB,FALABELLA_AR_PUB logfile=FALABELLA_AR_expdp_20111214.log status=10 parallel=1 CONTENT=ALL flashback_scn=612654934

二、压缩dmp文件

gzip -9 FALABELLA_AR_20111214.DMP 


三、上传DUMP文件到目标库并解压。

gzip -d  FALABELLA_AR_20111214.DMP 


四、准备目标库上原有用户对象

CREATE TABLESPACE TBS_FALABELLA_AR LOGGING DATAFILE '/u01/oradata/oracle/TBS_FALABELLA_AR01.DBF' 
  SIZE 1024M AUTOEXTEND ON NEXT 64M MAXSIZE 4096M
  EXTENT MANAGEMENT LOCAL
/

DROP USER FALABELLA_AR_CORE CASCADE;
DROP USER FALABELLA_AR_CATA CASCADE;
DROP USER FALABELLA_AR_CATB CASCADE;
DROP USER FALABELLA_AR_PUB CASCADE;

CREATE USER FALABELLA_AR_CORE IDENTIFIED BY FALABELLA_AR_CORE QUOTA UNLIMITED ON TBS_FALABELLA_AR
DEFAULT TABLESPACE TBS_FALABELLA_AR
TEMPORARY TABLESPACE TEMP;

GRANT CONNECT, RESOURCE TO FALABELLA_AR_CORE;

CREATE USER FALABELLA_AR_CATA IDENTIFIED BY FALABELLA_AR_CATA QUOTA UNLIMITED ON TBS_FALABELLA_AR
DEFAULT TABLESPACE TBS_FALABELLA_AR
TEMPORARY TABLESPACE TEMP;

GRANT CONNECT, RESOURCE TO FALABELLA_AR_CATA;

CREATE USER FALABELLA_AR_CATB IDENTIFIED BY FALABELLA_AR_CATB QUOTA UNLIMITED ON TBS_FALABELLA_AR
DEFAULT TABLESPACE TBS_FALABELLA_AR
TEMPORARY TABLESPACE TEMP;

GRANT CONNECT, RESOURCE TO FALABELLA_AR_CATB;

CREATE USER FALABELLA_AR_PUB IDENTIFIED BY FALABELLA_AR_PUB QUOTA UNLIMITED ON TBS_FALABELLA_AR
DEFAULT TABLESPACE TBS_FALABELLA_AR
TEMPORARY TABLESPACE TEMP;

GRANT CONNECT, RESOURCE TO FALABELLA_AR_PUB;

五、导入

--第一次导入
impdp system/oracle@oracle DIRECTORY=DATA_PUMP_DIR DUMPFILE=FALABELLA_AR_20111214.DMP LOGFILE=FALABELLA_AR_impdp_ALL_20111215.log  SCHEMAS=FALABELLA_AR_CORE,FALABELLA_AR_CATA,FALABELLA_AR_CATB,FALABELLA_AR_PUB REMAP_TABLESPACE=TBS_FALABELLA:TBS_FALABELLA_AR CONTENT=ALL PARALLEL=1 STATUS=10 TABLE_EXISTS_ACTION=REPLACE TRANSFORM=segment_attributes:n:table


导入时发现源库和目标库的字符集不一样,导入的时候虽然完成了,但有一些字段在字符转换的时候报出字段长度不够。检查日志,发现很多如下错误:

ORA-02374: conversion error loading table "FALABELLA_AR_PUB"."RGLLEVVF"
ORA-12899: value too large for column XAPM_NOVIA (actual: 16, maximum: 15)
ORA-02372: data for row: XAPM_NOVIA : 0X'4F4C4D45D14F202020202020202020'

于是想出一个办法,先单独导入元数据,然后查找日志,找出所有字段长度有问题的表,把相应的列长度改长:

--单独导入元数据
impdp system/oracle@oracle DIRECTORY=DATA_PUMP_DIR DUMPFILE=FALABELLA_AR_20111214.DMP LOGFILE=FALABELLA_AR_impdp_METADATA_ONLY_DISABLE_CONSTRAINT_20111215.log  SCHEMAS=FALABELLA_AR_CORE,FALABELLA_AR_CATA,FALABELLA_AR_CATB,FALABELLA_AR_PUB REMAP_TABLESPACE=TBS_FALABELLA:TBS_FALABELLA_AR CONTENT=METADATA_ONLY PARALLEL=1 STATUS=10 TABLE_EXISTS_ACTION=REPLACE TRANSFORM=segment_attributes:n:table


--查找日志,找出相应的错误,并修改列
ALTER TABLE FALABELLA_AR_CORE.DCSPP_SHIP_ADDR MODIFY (FIRST_NAME VARCHAR2(50));
ALTER TABLE FALABELLA_AR_PUB.RGLLEVVF MODIFY (  XNMB_NOVIO CHAR(30 BYTE), XAPP_NOVIO CHAR(30 BYTE),  XAPM_NOVIO CHAR(30 BYTE), XNMB_NOVIA CHAR(30 BYTE), XAPP_NOVIA CHAR(30 BYTE), XAPM_NOVIA CHAR(30 BYTE));
ALTER TABLE FALABELLA_AR_CORE.DPS_USER MODIFY ( LOGIN VARCHAR2(264 BYTE) NOT NULL);
ALTER TABLE FALABELLA_AR_CORE.FBL_CONTACT_INFO MODIFY ( EMAIL VARCHAR2(264 BYTE));
ALTER TABLE FALABELLA_AR_CORE.FBL_ELECTRONIC_SHIPPING MODIFY(SENDER_NAME VARCHAR2(64 BYTE));
ALTER TABLE FALABELLA_AR_CATA.FBL_STOCK_N_SHIP_WAREHOUSE MODIFY ( CUT_OFF_TIME VARCHAR2(10 BYTE));
ALTER TABLE FALABELLA_AR_CATB.FBL_STOCK_N_SHIP_WAREHOUSE MODIFY ( CUT_OFF_TIME VARCHAR2(10 BYTE));
ALTER TABLE FALABELLA_AR_PUB.FBL_STOCK_N_SHIP_WAREHOUSE MODIFY( CUT_OFF_TIME VARCHAR2(10 BYTE));
ALTER TABLE FALABELLA_AR_CORE.FBL_ORDER_BANK_PROMOTION MODIFY (BANK_NAME  VARCHAR2(30 BYTE));


然后再单独导入数据,但单独导入数据时由于先后关系,会检查参照完整性,于是先DISABLE所有的参照完整性,再导入数据,等导入完成后,再启用所有的参照完整性约束。

--报外键约束错误
ORA-31693: Table data object "FALABELLA_AR_CORE"."DCSPP_SHIPITEM_REL" failed to load/unload and is being skipped due to error:
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-02291: integrity constraint (FALABELLA_AR_CORE.DCSPP_SHRELTNSHP_F) violated - parent key not found

--于是,禁用所有外键约束
select 'ALTER TABLE '||OWNER||'.'||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||';' from dba_constraints where owner in('FALABELLA_AR_CORE','FALABELLA_AR_CATA','FALABELLA_AR_CATB','FALABELLA_AR_PUB') and CONSTRAINT_TYPE='R';

--单独导入数据
impdp system/oracle@oracle DIRECTORY=DATA_PUMP_DIR DUMPFILE=FALABELLA_AR_20111214.DMP LOGFILE=FALABELLA_AR_impdp_DATA_ONLY_DISABLE_CONSTRAINT__20111215.log  SCHEMAS=FALABELLA_AR_CORE,FALABELLA_AR_CATA,FALABELLA_AR_CATB,FALABELLA_AR_PUB REMAP_TABLESPACE=TBS_FALABELLA:TBS_FALABELLA_AR CONTENT=DATA_ONLY PARALLEL=1 STATUS=10 TRANSFORM=segment_attributes:n:table

--启用所有外键约束
select 'ALTER TABLE '||OWNER||'.'||TABLE_NAME||' ENABLE NOVALIDATE CONSTRAINT '||constraint_name||';' from dba_constraints where owner in('FALABELLA_AR_CORE','FALABELLA_AR_CATA','FALABELLA_AR_CATB','FALABELLA_AR_PUB') and CONSTRAINT_TYPE='R';


OK,大功告成,终于看到了久违的成功日志:

Job "SYSTEM"."SYS_IMPORT_SCHEMA_03" successfully completed at 07:29:24


你可能感兴趣的:(user,table,constraints,byte,attributes,parallel)