用IMP向测试库导入DMP时,又遇到了ORA-00959表空间不存在的问题。
一般的解决方法:
1.先建表,在导入dmp时加ignore=y 的参数。
2.新建对应的表空间
3.使用expdp从新导出,在impdp时用REMAP_TABLESPACE
无论用那种方法都比较麻烦,都需要耗费一定的工作量。如果在oracle10g中,
采用重命名表空间的方法,可以快速解决这个问题。
SQL> alter tablespace &old_tbsname rename to &new_tbs_name;
如当前用户默认的表空间为TEST,现在改为需要的表空间YWDBS
SQL> alter tablespace TEST rename to YWDBS;
/oracle$imp TEST/TEST file=dev_bak_20110702.dmp tables=PRPDRISK statistics=none
Import: Release 10.2.0.4.0 - Production on Wed Jul 6 09:39:25 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
Warning: the objects were exported by DEV, not by you
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing DEV's objects into REPORTTEST
. importing DEV's objects into REPORTTEST
IMP-00017: following statement failed with ORACLE error 959:
...
IMP-00003: ORACLE error 959 encountered
ORA-00959: tablespace 'YWDBS' does not exist
Import terminated successfully with warnings.
SQL> alter tablespace TEST rename to YWDBS;
重命名表空间后,会在alert.log中看到如下信息:
Tablespace 'TEST' is renamed to 'YWDBS'.
Completed: alter tablespace TEST rename to YWDBS
重命名表空间后,dmp可以顺利导入
/oracle$imp TEST/TEST file=dev_bak_20110702.dmp tables=PRPDRISK statistics=none
Import: Release 10.2.0.4.0 - Production on Wed Jul 6 10:05:08 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
Warning: the objects were exported by DEV, not by you
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing DEV's objects into REPORTTEST
. importing DEV's objects into REPORTTEST
. . importing table "PRPDRISK" 68 rows imported
Import terminated successfully without warnings.
为了管理上的规范,在导入成功后可以在将表空间名该回去。
IMP中的ORA-00959一般发生在有CLOB字段的表上。
一、导出文件
- 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