处理Oracle 11g在用EXP导出时,空表不能导出

一、问题原因: 
    11G中有个新特性,当表无数据时,不分配segment,以节省空间 

    想要给空表也分配segmant,有以下两个办法:


    1、insert一行,再rollback就产生segment了。 

        该方法是在在空表中插入数据,再删除,则产生segment。导出时则可导出空表。 

    2、设置deferred_segment_creation 参数 

show parameter deferred_segment_creation 

   NAME                                 TYPE        VALUE 

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

   deferred_segment_creation            boolean     TRUE 

   SQL> alter system set deferred_segment_creation=false; 

   系统已更改。 

   SQL> show parameter deferred_segment_creation 

   NAME                                 TYPE        VALUE 

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


   deferred_segment_creation            boolean     FALSE 

    该参数值默认是TRUE,当改为FALSE时,无论是空表还是非空表,都分配segment。 

    需注意的是:该值设置后对以前导入的空表不产生作用,仍不能导出,只能对后面新增的表产生作用。如需导出之前的空表,只能用第一种方法。 
View Code

二、解决方法: 

    1、先查询一下当前用户下的所有空表 

select table_name from user_tables where NUM_ROWS=0; 
View Code

 2、用以下这句查找空表 

select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 
View Code

     把查询结果导出,执行导出的语句

ALTERTABLE'||TABLE_NAME||'ALLOCATEEXTENT;' 

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

      alter table AQ$_AQ$_MEM_MC_H allocate extent; 

      alter table AQ$_AQ$_MEM_MC_G allocate extent; 

      alter table AQ$_AQ$_MEM_MC_I allocate extent; 

      alter table AQ$_AQ_PROP_TABLE_T allocate extent; 

      alter table AQ$_AQ_PROP_TABLE_H allocate extent; 

      alter table AQ$_AQ_PROP_TABLE_G allocate extent; 

      alter table AQ$_AQ_PROP_TABLE_I allocate extent; 

      alter table AQ$_KUPC$DATAPUMP_QUETAB_T allocate extent; 

      alter table AQ$_KUPC$DATAPUMP_QUETAB_H allocate extent; 

      alter table AQ$_KUPC$DATAPUMP_QUETAB_G allocate extent; 

      alter table AQ$_KUPC$DATAPUMP_QUETAB_I allocate extent; 
View Code

3、然后再执行 

       exp 用户名/密码@数据库名 file=/home/oracle/exp.dmp log=/home/oracle/exp_smsrun.log   成功!

当然了也可以用以下方法:expdp和impdp 

create directory expdp_dir as '/data/db';
grant read,write on directory expdp_dir to DRGN_OWNER;

expdp DRGN_OWNER/DRGN_OWNER DIRECTORY=expdp_dir DUMPFILE=dbfile.dmp SCHEMAS=DRGN_OWNER logfile=DRGN_OWNERexpdp.log

create directory impdp_dir as '/data/db'; 
grant read,write on directory impdp_dir to DRGN_OWNER;

impdp DRGN_OWNER/DRGN_OWNER DIRECTORY=impdp_dir DUMPFILE=dbfile.dmp logfile=DRGN_OWNER.dmpimpdp.log
View Code

然已经导入了

 对于DBA新建数据库,建议建立了空的数据库后,马上执行 

alter system set deferred_segment_creation=flase sscope=spfile; 
shutdowm immediate 
startup 
View Code

【小结】 

1、自己没有好好学习11g的新特性,导致了这个问题花费了2个小时的 
2、建议客户使用稳定的10.2.0.4,客户拒绝,现在11g已经是主流了,并不是每一个客户都很保守使用稳定版本,而非最新版本 
3、某美 和 某ELL 的项目以后少接触,4年前IBM P570双机Oracle10g的实施问题就折腾的无语。 
4、再次论证了很多甲方和厂商基本都是:事前猪一样,事后诸葛亮。和目前国内流行的砖家叫兽有异曲同工之妙。 
5、做技术果然是一条不归之路 

原文地址:https://www.cnblogs.com/fameg/p/9770487.html