zoukankan      html  css  js  c++  java
  • [转]--impdp操作产生大量UNDO的原因及解决方法

    在IMPDP Job期间产生大量UNDO的大部分原因都是因为在目标数据库导入的表已经存在,并且在这个表上存在一个或多个的索引。在impdp job期间,插入的每一行都需要维护索引。

        要解决这个问题,请确保在目标数据库不存在需要导入的表,之后让impdp来创建表。也就是说在执行impdp DataPump job的时候不要使用TABLE_EXISTS_ACTION=APPEND或者TABLE_EXISTS_ACTION=TRUNCATE参数,除非是真正必须要使用。

        如果一个大数据量需要导入一个存在表,你不得不使用TABLE_EXISTS_ACTION=APPEND,那么请执行以下的步骤:
    1).在目标数据库执行存在表的export,以至于在需要的时候能够恢复表的数据和相关对象的DDL操作。
    2).如果在目标数据库存在的表上有触发器,如果可能考虑DROP它们。
    3).确保在表上没有主键(索引),(如果你的目的是为了防止重复行,你必须要保留主键约束,这将不可避免在相关索引import job期间产生UNDO)。
    4).如果在目标数据库存在的表上包含其它的索引,如果可能考虑DROP它们(注意在执行impdp期间使用EXCLUDE=INDEX不能跳过任何存在索引的维护工作)。
    5).将数据导入目标数据库存在的表中。
    6).重建索引、主键和触发器。

        DataPump会选择最佳的方法确保数据和元数据以最有效的方法完成导出和导入。
        默认情况在impdp期间,Impdp将维护索引,如果表和索引已经创建,不要使用direct_path,然而,如果没有索引强制约束,可以在DataPump导入命令行指定ACCESS_METHOD=DIRECT_PATH,DataPump能使用直接路径(direct path)方法实施导入。

        也可以通过禁用主键约束来实现直接路径加载数据(使用ALTER TABLE ... MODIFY CONSTRAINT ... DISABLE NOVALIDATE),之后在impdp期间使用access_method=direct_path参数加载数据,最后启用主键约束(使用ALTER TABLE ... MODIFY CONSTRAINT ... ENABLE VALIDATE)。

        在导入期间不创建索引消耗UNDO是非常小的,下面是一个很好的数据导出、导入案例(案例转载自:http://www.anbob.com/archives/1888.html):

    因一次硬件原因导致了服务器异常停机,防止蝴蝶效应及时进行了数据迁移,一周发现了这个决定正确的。
    申请了2小时的停机时间。因数据不大且表空间开始使用不规范决定用expdp数据泵方式迁移。
    在新设备
    1).raid10+安装OS
    2).安装oracle 10.2.0.1(single instance)+
    3).升级oracle 10.2.0.5
    4).建库,
    5).调整INSTANCE参数,调整temp tbs、redo file size、undo tbs大小
    6).创建app schema、创建dataindex tablespace
    用时1小时左右
    stop web app+挂通知
    stop listener
    sys@TOPBOX>select object_type,count(*) cnt from dba_objects where owner='TOPBOX' GROUP BY OBJECT_TYPE;
    OBJECT_TYPE                          CNT
    ------------------- --------------------
    SEQUENCE                             802
    PROCEDURE                             25
    DATABASE LINK                          2
    LOB                                    3
    TRIGGER                                3
    MATERIALIZED VIEW                      2
    TABLE                                 87
    FUNCTION                              12
    VIEW                                  41
    INDEX                                142
    sys@TOPBOX>@schemas_space
    SCHEMA                              Object type                                    Space [MB]
    ----------------------------------- --------------------------------------------- -----------
    ...
    TOPBOX                              INDEX                                            34102.25
                                        LOBINDEX                                              .19
                                        LOBSEGMENT                                            .44
                                        TABLE                                            31132.69
    ***********************************                                               -----------
    sum                                                                                  65235.56
    ...
    ######################
    expdp 用时14分钟
    ######################
    expdp system/xxxxxx schemas=topbox directory=datapump dumpfile=newtopbox%U.dump filesize=5G parallel=6 logfile=topbox_parallel_expdp.log;
    [oracle@topbox datapump]$ du newtopbox0*
    829016 newtopbox01.dump
    5248012 newtopbox02.dump
    5248012 newtopbox03.dump
    5248012 newtopbox04.dump
    4338316 newtopbox05.dump
    3681564 newtopbox06.dump
    2029228 newtopbox07.dump
    673872 newtopbox08.dump
    80164 newtopbox09.dump
    [oracle@topbox datapump]$ du newtopbox0*|awk ‘{sum += $1};END {print sum}’
    27376196
    TIP:
    DUMP file only contains of indexes metadata data.
    #######################
    scp 用时11分钟
    #######################
    同为两台服务器DELL 2950 ,找个闲置网卡端口设置任意同网段IP,如192.168.0.1和192.168.0.2,用平时用的交叉线(不一定要直连线)网线不经交换机直连两台机器,发现有自适应很方便。
    scp传输dump文件到另一台机器,速度可达40MB/s.
    #########################
    IMPDP 用时16分钟 EXCLUDE=STATISTICS,constraint,index
    #########################
    impdp system/xxxxxxxx directory=datapump dumpfile=newtopbox%U.dump EXCLUDE=STATISTICS,constraint,index remap_tablespace=users:topbox parallel=6
    #########################
    CREATE ConstraintS and INDEXS
    #########################
    impdp username/XXXX directory=xxx DUMPFILE=newtopbox%U.dump SQLFILE=create_index.sql INCLUDE=constraint,index remap_tablespace=users:topbox_idx
    TIP:
    Edit create_index.sql, Replaced the degree of parallel and nologging options

    Bug 8604502 – IMPDP creates indexes with parallel degree 1 during import
    This issue is fixed in:
    12.1 (Future Release)
    11.2.0.2 (Server Patch Set)
    11.2.0.1 Bundle Patch 7 for Exadata Database
    11.1.0.7 Patch 24 on Windows Platforms

    References MACLEAN‘s post Speed up the index creation.
    alter session set workarea_size_policy=MANUAL;
    alter session set db_file_multiblock_read_count=512;
    alter session set events '10351 trace name context forever, level 128';
    alter session set sort_area_size=734003200;
    alter session set "_sort_multiblock_read_count"=128;
    alter session enable parallel ddl;
    alter session set db_file_multiblock_read_count=512;
    alter session set db_file_multiblock_read_count=512;
    alter session set "_sort_multiblock_read_count"=128;
    alter session set "_sort_multiblock_read_count"=128;
    spool create_index.log
    @create_index.sql
    spool off
    #######################
    Compile invalid objects
    #######################
    begin
    dbms_utility.COMPILE_SCHEMA('TOPBOX');
    end
    /
    #########################
    Gather Schema Statistics
    #########################
    begin
    dbms_stats.gather_schema_stats(
    ownname          => 'TOPBOX',
    estimate_percent => dbms_stats.auto_sample_size,
    method_opt       => 'for all columns size 1',
    degree           => 7
    );
    end
    /
    TIP:
    METHOD_OPT was ‘FOR ALL COLUMNS SIZE 1′. This basically says to Oracle please only collect basic column statistics (min, max, distinct values etc.), do not collect histograms
    on these columns. For columns that are evenly distributed and for columns that are not referenced in SQL statements, this is perfectly adequate. If a column was unevenly
    distributed and detrimentally impacted the CBO’s costings of an execution plan, then one could generate histograms for those particular columns separately.
    ##################
    others
    ##################
    Configuration Oracle database automatically with the Linux OS startup and shutdown .
    http://www.anbob.com/archives/511.html
    Configuration ORACLE database backup job.


    参考文章:
       《Import DataPump - How To Limit The Amount Of UNDO Generation of an IMPDP job ? (文档 ID 1670349.1)》
       《Run Out Of Space On UNDO Tablespace Using DataPump Import/Export (文档 ID 735366.1)》

    --end--
     
    来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23135684/viewspace-1205538/,如需转载,请注明出处,否则将追究法律责任。
  • 相关阅读:
    实习的一些感想,感触,心得体会
    一张优惠券引发的血案(redis并发安全问题)
    Java各种对象(PO,BO,VO,DTO,POJO,DAO,Entity,JavaBean,JavaBeans)的区分
    Redis 集群
    Maven Pom文件标签详解
    Google Guava 基本工具
    context:component-scan的使用说明
    logback的简单分析
    轮询和长轮询
    StringUtils中 isNotEmpty 和isNotBlank的区别?
  • 原文地址:https://www.cnblogs.com/lizhishugen/p/10904708.html
Copyright © 2011-2022 走看看