Oracle 11g R2中exp不能导出空表的解决方法

Linux大全评论2K views阅读模式

Oracle 11g Realease 2(11.2.0.1)中,在导出空表的时候,会报错。查了一下原因,原来,该版本中做了一项优化,在建表的时候,不会分配存储空间,只有在第一次insert数据的时候,才会分配存储空间。这在系统中有很多空表时,能节省大量的存储空间。但是如果系统只有少量的空间时,就没什么必要。这项优化还会引起配额错误(Quota Errors),可参考这里。这个问题在11.2.0.2中得到了修复。

为此,oracle提供了一个deferred_segment_creation参数来进行配置,这个参数默认值为true。所以在创建表时如果没有把这个参数指定为false,那么创建之后,又没有添加任何数据,在使用exp导出时就会出错。来看官方文档解释:

Property

Description

Parameter type

Boolean

Default value

true

Modifiable

ALTER SESSION, ALTER SYSTEM

Range of values

true | false

Basic

No

DEFERRED_SEGMENT_CREATION specifies the semantics of deferredsegment creation. If set to true, then segments for non-partitioned tables and their dependent objects (LOBs, indexes) will not be created untilthe first row is inserted into the table.

Before creating a set of tables, if it is known that asignificant number of them will not be populated, then consider setting thisparameter to true. This saves disk space and minimizes install time.

指定段延迟创建,如果设置成true,那么非分区表和依赖它的对象(LOB,索引)将不分配存储空间,直到往表中插入第一条数据时才分配。

在创建表之前,如果知道不会往里面写入数据,那可心考虑把这个参数设置成true。这样可以节省存储空间并减少表创建时间。

好,知道了原因,就好办了。来看解决办法:

1、最傻X的方法就是往表中写一条数据,然后删除或rollback掉,再导出就没问题了。但是这有个问题,如果有很多的表,那太费时间了。那就用第二种方法。

2、通过修改deferred_segment_creation参数。

查看该参数的值:

SQL> showparameter deferred_segment_creation; 
NAME                                TYPE        VALUE 
------------------------------------ ----------------------------------------- 
deferred_segment_creation          boolean    TRUE 

设置该参数:

alter system set deferred_segment_creation = false; 

设置该参数的语法如下:

set deferred_segment_creation = [TRUE | FALSE]

也可在创建表的时候指定,语法如下:

segment creation { IMMEDIATE | DEFERRED } 

这样设置之后,以后再创建表时,就会分配segment了。但是之前创建的表还不没有分配。还需要强制给之前的表分配空间。

alter table <tablename> allocate extent 

由于表有可能有很多,所以可使用下面方法来批量修改: 

select'altertable' ||table_name || ' allocate extent;' 
  from user_tables 
 where num_rows =0; 

企鹅博客
  • 本文由 发表于 2019年7月13日 07:26:19
  • 转载请务必保留本文链接:https://www.qieseo.com/186835.html

发表评论