一、概述

最近在测试环境的一个oracle数据库上面,使用exp将表导出没有问题,而将导出的文件使用imp导入时却出现了如下错误。
IMP-00009: abnormal end of export file
Import terminated successfully with warnings.

经过反复实验,终于找出问题出现的原因,是由以下几点共同造成的:
a. 数据库中参数deferred_segment_creation设置的是默认值true,即创建表的时候不立即分配段,等有行的时候才会分配段。
b. 导出的表中有分区表,而恰好该分区表存在分区没有行的情况,即有的分区没有分配段。
c. 导出时使用了direct=true。

解决办法直接看(三、解决办法)

二、问题复现

1. 准备工作

在测试库中准备两个用户,tom(导出的用户),jerry(导入的用户),分别给予其最大的权限。
SQL> create user tom identified by tom;
SQL> grant dba to tom;
SQL> create user jerry identified by jerry;
SQL> grant dba to jerry;

2. 检查数据库中参数deferred_segment_creation

SQL> show parameter deferred

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
deferred_segment_creation boolean TRUE

可以看到该参数是true,默认值。

3. 创建测试表

SQL> create table tom.t_normal as select * from scott.emp;  // 创建一张普通表,并且有行

SQL> create table tom.t_norows as select * from scott.emp where 1=0;  // 创建一张空表

SQL> create table tom.t_par(id number, name varchar2(10))
partition by list(id)
(partition p01 values(1),
partition p02 values(default));  // 创建一张分区表,两个分区

SQL> insert into tom.t_par values(1, 'aa');  // 往分区p01插入一条数据
SQL> commit;

至此,tom用户下有三张表,t_normal是普通表,t_norows是一张普通的空表,t_par是分区表。

通过下面的sql查到tom用户下只有两个segment,空表和分区表中无数据的分区都没有创建段。

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

OWNER      SEGMENT_NAME         PARTITION_NAME                 SEGMENT_TYPE
---------- -------------------- ------------------------------ ------------------
TOM T_NORMAL TABLE
TOM T_PAR P01 TABLE PARTITION

4. 使用tom对表进行导出

exp tom/tom file=tom.dmp log=tom_exp.log direct=true

导出日志如下(省略部分无关内容):
. . exporting table                       T_NORMAL         14 rows exported
. . exporting table                       T_NOROWS          0 rows exported
. . exporting table                          T_PAR
. . exporting partition                            P01          1 rows exported
. . exporting partition                            P02          0 rows exported
Export terminated successfully without warnings.

5. 使用jerry对文件进行导入

imp jerry/jerry file=tom.dmp log=jerry_imp.log fromuser=tom touser=jerry

导入日志如下(省略部分无关内容):
. . importing table                     "T_NORMAL"         14 rows imported
. . importing table                     "T_NOROWS"          0 rows imported
. . importing partition                  "T_PAR":"P01"          1 rows imported
. . importing partition                  "T_PAR":"P02"
IMP-00009: abnormal end of export file
Import terminated successfully with warnings.
生产上面出现的错误在这里就得到复现了。而且是在导入"T_PAR":"P02"出现的错误,这个正好印证了前面的观点。

三、解决办法

解决办法有以下两种(任一即可):
a. 使用exp导出的时候不要加direct=true
b. 设置数据库的参数deferred_segment_creation为false(注意:这个参数只影响新建的分区表,老的分区表导出再导入仍然会报错!)

四、有时间、有兴趣的读者可以接着做实验

可能大家会问,你怎么知道是分区表的问题,又怎么知道是direct=true的问题,又怎么知道是参数deferred_segment_creation的问题?接下来我一一验证。

1. 清空jerry的表,导出tom用户下表t_normal,t_norows,再导入到jerry用户中

SQL> drop user jerry cascade;  // 通过重建jerry用户来清空jerry的表
SQL> create user jerry identified by jerry;
SQL> grant dba to jerry;

exp tom/tom file=tom.dmp log=tom_exp.log direct=true tables=t_normal,t_norows
导出日志:
. . exporting table                       T_NORMAL         14 rows exported
. . exporting table                       T_NOROWS          0 rows exported
Export terminated successfully without warnings.

imp jerry/jerry file=tom.dmp log=jerry_imp.log fromuser=tom touser=jerry
导入日志:
. . importing table                     "T_NORMAL"         14 rows imported
. . importing table                     "T_NOROWS"          0 rows imported
Import terminated successfully without warnings.

可以看到对这两张表导入是没有问题的

2. 清空jerry的表,导出tom用户下表t_par,再导入到jerry用户中

清空jerry的表的操作请看上面的步骤

exp tom/tom file=tom.dmp log=tom_exp.log direct=true tables=t_par
导出日志:
. . exporting table                          T_PAR
. . exporting partition                            P01          1 rows exported
. . exporting partition                            P02          0 rows exported
Export terminated successfully without warnings.

imp jerry/jerry file=tom.dmp log=jerry_imp.log fromuser=tom touser=jerry
导入日志:
. importing TOM's objects into JERRY
. . importing partition                  "T_PAR":"P01"          1 rows imported
. . importing partition                  "T_PAR":"P02"
IMP-00009: abnormal end of export file
Import terminated successfully with warnings.

可以看到问题就出在对这张分区表的导入上面了

3. 清空jerry的表,重新导出tom用户下表t_par,再导入到jerry用户中(这次导出不加参数direct=true)

清空jerry的表的操作请看上面的步骤

exp tom/tom file=tom.dmp log=tom_exp.log tables=t_par
导出日志:
. . exporting table                          T_PAR
. . exporting partition                            P01          1 rows exported
. . exporting partition                            P02          0 rows exported
Export terminated successfully without warnings.

imp jerry/jerry file=tom.dmp log=jerry_imp.log fromuser=tom touser=jerry
导入日志:
. importing TOM's objects into JERRY
. . importing partition                  "T_PAR":"P01"          1 rows imported
. . importing partition                  "T_PAR":"P02"          0 rows imported
Import terminated successfully without warnings.

可以看到这次导入没有任何问题,也就是说不加direct=true直接可以解决问题,但是如果我非要加这个参数呢,或者说这个命令写死到程序中了,没办法改怎么办?处理办法看下面第6条。

4. 清空jerry的表,在tom.t_par的p02分区中插入一条数据,重新导出tom用户下表t_par,再导入到jerry用户中(这次导出依然加参数direct=true)

清空jerry的表的操作请看上面的步骤

SQL> insert into tom.t_par values(2, 'bb');  // 往分区p02插入一条数据
SQL> commit;

通过下面的sql查到t_par两个分区都有段了。

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

OWNER      SEGMENT_NAME         PARTITION_NAME                 SEGMENT_TYPE
---------- -------------------- ------------------------------ ------------------
TOM T_PAR P01 TABLE PARTITION
TOM T_PAR P02 TABLE PARTITION
TOM T_NORMAL TABLE

exp tom/tom file=tom.dmp log=tom_exp.log direct=true tables=t_par
导出日志:
. . exporting table                          T_PAR
. . exporting partition                            P01          1 rows exported
. . exporting partition                            P02          1 rows exported
Export terminated successfully without warnings.

imp jerry/jerry file=tom.dmp log=jerry_imp.log fromuser=tom touser=jerry
导入日志:
. importing TOM's objects into JERRY
. . importing partition                  "T_PAR":"P01"          1 rows imported
. . importing partition                  "T_PAR":"P02"          1 rows imported
Import terminated successfully without warnings.

可以看到分区表中所有分区都有数据的话,导入就没有任何问题,

5. 验证deferred_segment_creation参数对其的影响

清空jerry的表的操作请看上面的步骤

修改数据库中参数deferred_segment_creation为false
SQL> alter system set deferred_segment_creation=false;

重建tom用户的t_par表,让其一个分区有数据,另外一个分区无数据
SQL> drop table tom.t_par;

SQL> create table tom.t_par(id number, name varchar2(10))
partition by list(id)
(partition p01 values(1),
partition p02 values(default));  // 创建一张分区表,两个分区

SQL> insert into tom.t_par values(1, 'aa');  // 往分区p01插入一条数据
SQL> commit;

通过下面的sql查到t_par两个分区都有段了,即使p02分区里面没有数据

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

OWNER      SEGMENT_NAME         PARTITION_NAME                 SEGMENT_TYPE
---------- -------------------- ------------------------------ ------------------
TOM T_PAR P01 TABLE PARTITION
TOM T_PAR P02 TABLE PARTITION
TOM T_NORMAL TABLE

exp tom/tom file=tom.dmp log=tom_exp.log direct=true tables=t_par
导出日志:
. . exporting table                          T_PAR
. . exporting partition                            P01          1 rows exported
. . exporting partition                            P02          0 rows exported
Export terminated successfully without warnings.

imp jerry/jerry file=tom.dmp log=jerry_imp.log fromuser=tom touser=jerry
导入日志:
. importing TOM's objects into JERRY
. . importing partition                  "T_PAR":"P01"          1 rows imported
. . importing partition                  "T_PAR":"P02"          0 rows imported
Import terminated successfully without warnings.

可以看到将参数deferred_segment_creation修改为false导入也正常,但是这只适用于新建的分区表,对于已经存在的分区表,依然会导入失败。处理办法看下面第6条。

6. 接下来回答上面第3和5步中的问题

如果想用exp,imp进行导出导入,导出的时候又必须加direct=true,而且导出的表中包含分区表,并且该分区表中存在分区没有段的情况。那怎么办?
光是将参数deferred_segment_creation修改为false不够,因为这只影响新建的表,要想对老的表也生效,可以采取下面的办法。

6.1. 将参数deferred_segment_creation修改为false
SQL> alter system set deferred_segment_creation=false;

6.2. 使用exp对分区表进行导出(只有那些分区表中存在分区没有分配段的才需要导出),注意不要加direct=true
exp tom/tom file=tom.dmp log=tom_exp.log tables=t_par

6.3. 删除该分区表
SQL> drop table tom.t_par;

6.4. 使用imp对其进行导入
imp tom/tom file=tom.dmp log=tom_imp.log full=y

导入日志
. importing TOM's objects into TOM
. . importing partition                  "T_PAR":"P01"          1 rows imported
. . importing partition                  "T_PAR":"P02"          0 rows imported
Import terminated successfully without warnings.

导入后查看段的情况

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

OWNER      SEGMENT_NAME         PARTITION_NAME                 SEGMENT_TYPE
---------- -------------------- ------------------------------ ------------------
TOM T_PAR P02 TABLE PARTITION
TOM T_PAR P01 TABLE PARTITION

可以看到现在即使P02分区中没有行,也分配了段。这是由于我先前已经将参数deferred_segment_creation设置成了false,并且删除了表,imp在执行过程中,会先创建表然后插入数据,在创建表时,每个分区都会分配段。也就是说只需要解决老的分区表中段没有分配的情况,后面就不会碰到IMP-00009。

五、总结

只有在分区表中存在分区没有分配段,而且在导出时使用了direct=true参数,这两种情况在一起才会造成我这个IMP-00009这个错误。对于其它的普通表,不管有没有分配段,是否使用direct=true都不会造成这个错误。

我在分析IMP-00009这个问题的时候,首先日志纪录只有一行,就写"IMP-00009: abnormal end of export file",第一时间去查导出的日志,"Export terminated successfully without warnings.",导出的日志没有显示任何异常。这就把我整懵逼了。然后我开始求助于万能的互联网,查了一圈下来,没有找到任何解决方案,其实不是大牛不解答,而是问问题的人提供的信息太少了,你就提供个错误日志,比方说我这次碰到的问题,假设你只给个错误日志,大牛打死也复现不出来问题,那就谈不上去解决问题了。而往往当我们把整个问题都描述清楚了,问题大概率就迎刃而解了。

文章中涉及到的相关信息备注:
deferred_segment_creation:延迟段创建,上面已经通过实验介绍的很清楚了。
direct=true:导出数据时不经过buffer cache,这个参数是个天坑,bug极多,导出时尽量不要用。

IMP-00009: abnormal end of export file解决方案的更多相关文章

  1. IMP-00008: unrecognized statement in the export file: string的问题分析

    分类: Linux 上周需要将oracle10g中的某一个用户下的对象导入到oracle11g中去.用exp在10g的数据库服务器上导出的dump文件,再用imp在11g的数据库服务器上将dump文件 ...

  2. 【Oracle】IMP-00010: not a valid export file, header failed verification

    别人给了一个Oracle文件,结果在导入的时候发现有问题,报错如下: IMP-00010: not a valid export file, header failed verification 在网 ...

  3. Unknown class in Interface Builder file 解决方案

    在用swift项目打包Framework时,在项目中使用包时,报错: Unknown class in Interface Builder file... 网上很多解决方案,都不适合我的场景 最终解决 ...

  4. [OpenGL] mac上运行NateRobin的OpenGL教程找不到 data file 解决方案

    之前买的OpenGL编程指南第七版一直没看,最近开始看了,然后按照教程推荐的去指定网址下载NateRobin的OpenGL教程,但发现网址已经提示Error:404了, 然后谷歌搜索到可用的下载网址为 ...

  5. vcftools报错:Writing PLINK PED and MAP files ... Error: Could not open temporary file.解决方案

    一般来说有两种解决方案. 第一种:添加“--plink-tped”参数: 用vcftools的“--plink”参数生成plink格式文件时,小样本量测试可以正常生成plink格式,用大样本量时产生W ...

  6. java.lang.UnsupportedClassVersionError: Bad version number in .class file 解决方案

    在Myeclipse中运行小应用程序时出现如下异常的解决办法 java.lang.UnsupportedClassVersionError: Bad version number in .class ...

  7. Unity3D发布WebPlayer时Failed to download data file解决方案

    今天发布WebPlayer时, 发现直接打开html是可以正常运行的, 但是通过iis访问的话就会报错: Failed to download data file. 一开始以为是防火墙, 后来发现不是 ...

  8. Android proguard混淆签名打包出现"android proguard failed to export application"解决方案

    刚刚接触安卓,不是很熟悉.发现之前可以正常打包的项目出现添加混淆再进行打包签名的APK之后提示"android proguard failed to export application&q ...

  9. electron builder 打包错误 cannot unpack electron zip file 解决方案

    npm run buildwin > study01@1.0.0 buildwin F:\Nodejs\electron\Test\study01> electron-builder -- ...

随机推荐

  1. 分享一个mysql服务启动与关闭的bat文件

    有时候打开数据库可视化工具(sqlyog.navicat)连接数据库时,会出现以下报错信息. 大家都知道是数据库的服务没有启动. 所以我想给大家分享一个bat文件可供快速启动mysql的数据库的服务, ...

  2. NodeJS4-8静态资源服务器实战_构建cli工具

    Cli(command-line interface),中文是 命令行界面,简单来说就是可以通过命令行快速生成自己的项目模板等功能(比较熟悉的是vue-cli脚手架这些),把上述写的包做成Cli工具. ...

  3. SpringCloud-使用路由网关的服务过滤功能-拦截登录前是否有token为例

    场景 SpringCloud-使用路由网关统一访问接口(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102733 ...

  4. 查询BPC动态表

    今天BASIS说后台有张数据表(/1CPMB/ABLBCAD)数据量已超过20亿,需要归档,但是不清楚是哪个业务模型. 有两种方式可以查询BPC动态生成的表名. (1)根据命名规则 环境前缀:apps ...

  5. 管道及 I/O 重定向

    I/O重定向 I/O Redirection 标准输入.标准输出.标准错误输出重定向及综合案例输入重定向及结合案例 标准输入.标准输出.标准错误 file descriptors (FD,文件描述符 ...

  6. Pikachu-XSS

    XSS(跨站脚本)概述 Cross-Site Scripting 简称为“CSS”,为避免与前端叠成样式表的缩写"CSS"冲突,故又称XSS.一般XSS可以分为如下几种常见类型: ...

  7. 相机位姿求解——P3P问题

    1.位姿求解是计算机视觉中经常遇到的,Perspective-n-Points, PnP(P3P)提供了一种解决方案,它是一种由3D-2D的位姿求解方式,即需要已知匹配的3D点和图像2D点.目前遇到的 ...

  8. 做了这么久的程序员,你知道为什么会有 Lambda 表达式吗?

    Java8 有一些新的特性,今天老顾给大家分享一下关于 Lambda 表达式的由来,一开始感觉 Lambda 可读性蛮差的,不知道 为什么 Java8 会出来这个表达式?既然大佬们推出来,肯定是有原因 ...

  9. Java程序员月薪三万,需要技术达到什么水平?

    最近跟朋友在一起聚会的时候,提了一个问题,说 Java 程序员如何能月薪达到二万,技术水平需要达到什么程度?人回答说这只能是大企业或者互联网企业工程师才能拿到.也许是的,小公司或者非互联网企业拿二万的 ...

  10. WPF之实现控件内容拖动

    以下分别记录label.listbox.treeview三个控件的拖动示例: 1.对被拖动控件,实现拖动事件,主要是通过各种鼠标事件,实现DragDrop.DoDragDrop方法. 2.对于需要拖动 ...