oracle ora 39111,Impdp ORA-39083、ORA-01403报错问题分析解决

数据泵(Data Pump)是从10g开始推出的新一代数据逻辑备份还原工具。从产品线角度看,Data Pump是用于替换Exp/Imp传统工具的。经过若干版本的演进,Data Pump的兼容性和优秀特性已经逐步被接受。但是,在一些特殊的应用场景下,还是有Bug或者故障的存在。

本篇主要介绍笔者在工作中遇到的一个Impdp过程中出现ORA-39083和ORA-01403联合错误故障,并且通过MOS官方找到解决方案的过程。

1、问题说明

笔者进行一个数据库的导出导入操作,在impdp操作的时候发现了错误提示信息。

ORA-39083: Object type INDEX_STATISTICS failed to create with error:

ORA-01403: no data found

ORA-01403: no data found

Failing sql is:

DECLARE I_N VARCHAR2(60);I_O VARCHAR2(60);NV VARCHAR2(1);c DBMS_METADATA.T_VAR_COLL;df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS';stmt varchar2(300) := ' INSERT INTO "SYS"."IMPDP_STATS" (type,version,flags,c1,c2,c3,c5,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,d1,cl1) VALUES (''I'',6,:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,NULL,:14,:15,NULL,:16,:17)';BEGINDELETE

(重复若干次,篇幅原因,有所省略……)

Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS

Processing object type SCHEMA_EXPORT/VIEW/VIEW

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

Job "SYS"."SYS_IMPORT_FULL_01" completed with 153 error(s) at Thu Aug 27 10:20:39 2015 elapsed 0 00:04:05

从内容结构看,是在统计量导入的时候发生的错误信息。插入之前数据表和索引创建过程已经结束了。而且,操作数据表SQL语句涉及数据表是impdp_stats,是一个Oracle内部数据表。

经过检查,数据表起码都在,也没有发现明显的错误内容。在MOS上面,发现该问题还是有比较大的问题缺陷的。

2、问题分析

在MOSID 755253.1 DataPump Import (IMPDP) Failed With Errors ORA-39083 ORA-1403 On INDEX_STATISTICS中,对这个问题有比较详细的叙述。

Impdp程序在操作上,是遵循类型原则进行导入,也就是相同类型对象一次性处理。在下面的实例中,我们可以看到Impdp的操作过程。

Import: Release 11.2.0.4.0 - Production on Thu Aug 27 11:38:30 2015

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 "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded

Starting "SYS"."SYS_IMPORT_FULL_01":"/******** AS SYSDBA" dumpfile=test.dmp remap_schema=scott:sys

Processing object type TABLE_EXPORT/TABLE/TABLE –数据表元数据

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA–插入数据

. . imported "SYS"."DEPT"5.960 KB5 rows

Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX –创建索引

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT –创建约束

Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS –索引统计量

Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS –数据表统计量

Job "SYS"."SYS_IMPORT_FULL_01" successfully completed at Thu Aug 27 11:38:32 2015 elapsed 0 00:00:01

在上面的过程中,我们可以看到Oracle Impdp导入过程步骤顺序:

ü数据表元数据,依次执行数据表创建DDL;

ü数据表数据,直接写入数据表中。由于没有约束和索引,所以这个过程数据插入是很快的;

ü索引对象,创建索引对象;

ü约束对象,包括主外键等约束;

ü索引统计量;

ü数据表统计量;

通常情况下,这个过程是没有过多问题的。但是由于主键约束的特性,能够引起一些问题。

主键Primary Key是我们经常使用的一种约束,但是这种约束也存在一些副效应,就是连带索引创建。

SQL> create table t as select * from user_objects;

Table created

SQL> alter table t add constraint pk_t primary key(object_id) ;

Table altered

SQL> select segment_name, segment_type from user_segments;

SEGMENT_NA SEGMENT_TYPE

---------- ---------------

TTABLE

PK_TINDEX

如果我们创建一个命名的主键约束,系统后连带的创建一个同名的索引对象。如果我们在创建约束的时候没有命名,系统会自动的创建一个命名对象。

SQL> create table t_r as select * from user_objects;

Table created

SQL> alter table t_r add (primary key (object_id));

Table altered

SQL> col segment_name for a20;

SQL> select segment_name, segment_type from user_segments;

SEGMENT_NAMESEGMENT_TYPE

-------------------- ---------------

TTABLE

T_RTABLE

PK_TINDEX

SYS_C00131925INDEX

注意:这个名称是系统自动生成的。在导出之后,系统导入的时候,对这些缺失名称的索引会采用在目标库中的新名字。而且,这些系统名称索引会在正式给定名称索引之后才能创建(作为约束生成的副效应)。

在导入的时候,根据impdp的工作顺序,Oracle会先创建显示命名的索引,之后才会创建约束,这时候才会创建连带的创建索引。对命名主键索引而言,当约束生成的时候,Oracle发现已经有了命名索引,就不会再去创建系统索引了。后续,系统在进行索引统计量导入的时候,自然也就报错找不到数据了。

这个错误在Oracle被认为是一个Bug,Bug编号是8615836:ORA-1403 OCCURS DURING IMPORTING TABLE_STATISTICS IN IMPDP, closed as not feasible to fix。

那么,这种错误会有什么长期影响呢?就是索引丢失,笔者发现,这种错误下是会出现源数据库导入之后,一些索引丢失的现象。

解决方案,Oracle提供了几种:

ü修改创建主键约束的方法,不要使用系统自动生成的主键名称,而是进行全部命名;

ü将索引导入动作import indexes分拆出操作步骤,也就是先进行数据表、约束导入,之后手工进行索引导入。这样就让主键约束先建立命名索引或者系统自动名称索引;

ü最后,就是使用exp/imp传统工具;

笔者认为:第二种方法是对通常DBA最好的策略。如果是开发阶段,主键约束显示命名应当作为一条开发规范在系统中落实。一般DBA遇到的情况下,往往是没有精力进行快速的处理。

下面,笔者通过实验去演示问题发生、索引缺失现象和第二种处理方法。

3、演示实验

笔者通过两个实验数据表,来演示问题现象。实验环境为11gR2,具体版本为11.2.0.4。

SQL> select * from v$version;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

PL/SQL Release 11.2.0.4.0 - Production

CORE11.2.0.4.0Production

TNS for Linux: Version 11.2.0.4.0 - Production

NLSRTL Version 11.2.0.4.0 – Production

创建专门用户schema进行实验。

SQL> create user test identified by test;

User created

SQL> grant connect, resource to test;

Grant succeeded

SQL> create table t_bk as select * from dba_objects;

Table created

SQL> alter table t_bk add (primary key (object_id, object_name)); --无显示命名主键约束

Table altered

SQL> create index idx_t_bk on t_bk(object_name, object_id);

Index created

SQL> select segment_name, segment_type from user_segments;

SEGMENT_NAMESEGMENT_TYPE

--------------- --------------------

T_BKTABLE

SYS_C00124870INDEX

IDX_T_BKINDEX –其他索引

如果我们创建命名主键约束,如下:

SQL> create table t_ori as select * from t_bk;

Table created

SQL> alter table t_ori add constraint pk_t_oriprimary key (object_id, object_name);

Table altered

SQL> create index idx_t_ori_com on t_ori(object_name,object_id);

Index created

SQL> select segment_name, segment_type from user_segments;

SEGMENT_NAMESEGMENT_TYPE

--------------- ------------------------------------------------------------------------

T_ORITABLE

T_BKTABLE

SYS_C00124870INDEX

IDX_T_BKINDEX

PK_T_ORIINDEX

IDX_T_ORI_COMINDEX

6 rows selected

下面,进行导出和默认方式导入操作。

SQL> show user;

User is "SYS"

[oracle@localhost ~]$ expdp \"/ as sysdba\" dumpfile=test.dmp schemas=test

Export: Release 11.2.0.4.0 - Production on Thu Aug 27 15:10:23 2015

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 "SYS"."SYS_EXPORT_SCHEMA_01":"/******** AS SYSDBA" dumpfile=test.dmp schemas=test

Estimate in progress using BLOCKS method...

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 28 MB

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

. . exported "TEST"."T_BK"11.81 MB123146 rows

. . exported "TEST"."T_ORI"11.81 MB123146 rows

Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded

***************************************

Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:

/u01/app/admin/sicsdb/dpdump/test.dmp

Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Aug 27 15:10:36 2015 elapsed 0 00:00:13

尝试默认导入操作:

[oracle@localhost ~]$ impdp \"/ as sysdba\" dumpfile=test.dmp remap_schema=test:mt

Import: Release 11.2.0.4.0 - Production on Thu Aug 27 15:13:30 2015

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 "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded

Starting "SYS"."SYS_IMPORT_FULL_01":"/******** AS SYSDBA" dumpfile=test.dmp remap_schema=test:mt

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

. . imported "MT"."T_BK"11.81 MB123146 rows

. . imported "MT"."T_ORI"11.81 MB123146 rows

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

ORA-39083: Object type INDEX_STATISTICS failed to create with error:

ORA-01403: no data found

ORA-01403: no data found

Failing sql is:

DECLARE I_N VARCHAR2(60);I_O VARCHAR2(60);NV VARCHAR2(1);c DBMS_METADATA.T_VAR_COLL;df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS';stmt varchar2(300) := ' INSERT INTO "SYS"."IMPDP_STATS" (type,version,flags,c1,c2,c3,c5,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,d1,cl1) VALUES (''I'',6,:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,NULL,:14,:15,NULL,:16,:17)';BEGINDELETE

Job "SYS"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Thu Aug 27 15:13:35 2015 elapsed 0 00:00:04

注意:报错发生,而且报一个错误信息!这个很重要,说明在导入index统计量的时候一个索引发生问题。

检查结果:系统自命名索引缺失。

SQL> select segment_name, segment_type from dba_segments where owner='MT';

SEGMENT_NAMESEGMENT_TYPE

--------------- ------------------------------------------------------------------------

IDX_T_ORI_COMINDEX

PK_T_ORIINDEX

IDX_T_BKINDEX

T_ORITABLE

T_BKTABLE

处理方法,拆分为两步导入过程:

[oracle@localhost ~]$ impdp \"/ as sysdba\" dumpfile=test.dmp remap_schema=test:mt exclude=index

Import: Release 11.2.0.4.0 - Production on Thu Aug 27 15:21:22 2015

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 "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded

Starting "SYS"."SYS_IMPORT_FULL_01":"/******** AS SYSDBA" dumpfile=test.dmp remap_schema=test:mt exclude=index

Processing object type SCHEMA_EXPORT/USER

ORA-31684: Object type USER:"MT" already exists

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

. . imported "MT"."T_BK"11.81 MB123146 rows

. . imported "MT"."T_ORI"11.81 MB123146 rows

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Job "SYS"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Thu Aug 27 15:21:25 2015 elapsed 0 00:00:02

[oracle@localhost ~]$ impdp \"/ as sysdba\" dumpfile=test.dmp remap_schema=test:mt include=index

Import: Release 11.2.0.4.0 - Production on Thu Aug 27 15:21:49 2015

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 "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded

Starting "SYS"."SYS_IMPORT_FULL_01":"/******** AS SYSDBA" dumpfile=test.dmp remap_schema=test:mt include=index

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

ORA-31684: Object type INDEX:"MT"."PK_T_ORI" already exists

Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

ORA-39111: Dependent object type INDEX_STATISTICS skipped, base object type INDEX:"MT"."PK_T_ORI" already exists

Job "SYS"."SYS_IMPORT_FULL_01" completed with 2 error(s) at Thu Aug 27 15:21:52 2015 elapsed 0 00:00:02

查看索引创建:

SQL> select segment_name, segment_type from dba_segments where owner='MT';

SEGMENT_NAMESEGMENT_TYPE

--------------- ------------------------------------------------------------------------

PK_T_ORIINDEX

SYS_C00124889INDEX

IDX_T_ORI_COMINDEX

IDX_T_BKINDEX

T_ORITABLE

T_BKTABLE

6 rows selected

没有出现错误提示信息。

4、结论

数据备份、还原是我们经常使用的情况,其实也是用户最常使用的功能。针对各种问题错误,我们首先原则是数据完整性,数据丢失、对象丢失都是需要重视的问题方面。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值