云计算百科
云计算领域专业知识百科平台

DM-dimp 逻辑导入:达梦数据库数据迁移与恢复的核心利器

一、DM-dimp 逻辑导入概述

1.1 DM-dimp 工具简介

DM-dimp 是达梦数据库 (DM Database) 提供的官方逻辑导入工具,与逻辑导出工具 dexp 配套使用。DM-dimp 逻辑导入的核心职责是将 dexp 导出的二进制文件 (通常为 .dmp 格式) 解析并恢复到目标达梦数据库实例中,实现跨环境的数据迁移与数据恢复。

DM-dimp 工具具有以下核心特征:

  • 跨平台兼容: 支持 Windows、Linux 等主流操作系统,导出文件可在不同平台间迁移使用。
  • 多粒度导入: 支持全库 (FULL)、用户 (OWNER)、模式 (SCHEMAS)、表 (TABLES) 四种导入级别。
  • 灵活的对象控制: 可独立控制索引、约束、触发器、权限、统计信息等数据库对象的导入行为。
  • 并行加速: 支持设置并行度,充分利用多核 CPU 资源提升导入效率。
  • 1.2 DM-dimp 逻辑导入应用场景

    DM-dimp 逻辑导入在实际运维工作中覆盖以下典型场景:

  • 开发与测试环境数据同步: 将生产环境导出的数据集导入到开发或测试环境,保证环境间数据一致性。
  • 数据库版本升级迁移: 在达梦数据库大版本升级时,通过逻辑导入完成数据迁移。
  • 数据恢复与补救: 当发生误删除或数据损坏时,利用备份的 dmp 文件进行定向恢复。
  • 跨实例数据复制: 在不同达梦数据库实例之间复制特定的模式或表数据。
  • 异构数据库迁移: 从 Oracle 等数据库迁移至达梦数据库后的数据装载环节。
  • 1.3 DM-dimp 与 dexp 的协作关系

    DM-dimp 与 dexp 构成达梦数据库逻辑备份恢复的完整闭环。dexp 负责从源数据库导出数据为 dmp 文件,DM-dimp 负责将 dmp 文件导入到目标数据库。两者在文件格式、对象类型、级别划分上保持完全一致,确保导出数据能够被准确还原。

    #publish-mermaid-1786508095831-0{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-1786508095831-0 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786508095831-0 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786508095831-0 .error-icon{fill:#552222;}#publish-mermaid-1786508095831-0 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786508095831-0 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786508095831-0 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786508095831-0 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786508095831-0 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786508095831-0 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786508095831-0 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786508095831-0 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786508095831-0 .marker.cross{stroke:#333333;}#publish-mermaid-1786508095831-0 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786508095831-0 p{margin:0;}#publish-mermaid-1786508095831-0 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786508095831-0 .cluster-label text{fill:#333;}#publish-mermaid-1786508095831-0 .cluster-label span{color:#333;}#publish-mermaid-1786508095831-0 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786508095831-0 .label text,#publish-mermaid-1786508095831-0 span{fill:#333;color:#333;}#publish-mermaid-1786508095831-0 .node rect,#publish-mermaid-1786508095831-0 .node circle,#publish-mermaid-1786508095831-0 .node ellipse,#publish-mermaid-1786508095831-0 .node polygon,#publish-mermaid-1786508095831-0 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786508095831-0 .rough-node .label text,#publish-mermaid-1786508095831-0 .node .label text,#publish-mermaid-1786508095831-0 .image-shape .label,#publish-mermaid-1786508095831-0 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786508095831-0 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786508095831-0 .rough-node .label,#publish-mermaid-1786508095831-0 .node .label,#publish-mermaid-1786508095831-0 .image-shape .label,#publish-mermaid-1786508095831-0 .icon-shape .label{text-align:center;}#publish-mermaid-1786508095831-0 .node.clickable{cursor:pointer;}#publish-mermaid-1786508095831-0 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786508095831-0 .arrowheadPath{fill:#333333;}#publish-mermaid-1786508095831-0 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786508095831-0 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786508095831-0 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786508095831-0 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786508095831-0 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786508095831-0 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786508095831-0 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786508095831-0 .cluster text{fill:#333;}#publish-mermaid-1786508095831-0 .cluster span{color:#333;}#publish-mermaid-1786508095831-0 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#publish-mermaid-1786508095831-0 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786508095831-0 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786508095831-0 .icon-shape,#publish-mermaid-1786508095831-0 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786508095831-0 .icon-shape p,#publish-mermaid-1786508095831-0 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786508095831-0 .icon-shape .label rect,#publish-mermaid-1786508095831-0 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786508095831-0 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786508095831-0 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786508095831-0 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].node rect,#publish-mermaid-1786508095831-0 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786508095831-0 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095831-0 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095831-0 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}dexp 逻辑导出文件传输DM-dimp 逻辑导入数据验证

    源 DM 数据库

    dmp 文件

    目标服务器

    目标 DM 数据库

    导入完成

    二、DM-dimp 逻辑导入使用准备

    2.1 环境检查与前提条件

    在执行 DM-dimp 逻辑导入之前,需要完成以下环境检查工作:

  • 数据库实例状态确认: 确保目标达梦数据库实例已正常启动,可通过 disql 工具连接验证。
  • 磁盘空间评估: 确认目标服务器磁盘空间充足,建议可用空间为 dmp 文件大小的 2 至 3 倍。
  • 表空间与用户准备: 若导入涉及新的模式或用户,需提前在目标库中创建对应的表空间和用户。
  • 网络与端口检查: 确认目标数据库监听端口可正常访问,防火墙规则放行。
  • 字符集一致性: 检查源库与目标库的字符集是否一致,避免乱码问题。
  • 2.2 参数说明与常用选项

    DM-dimp 逻辑导入工具提供丰富的参数选项,以下为常用参数的详细说明:

    | 参数名称 | 参数说明 | 示例值 |

    |———|———|——-|

    | USERID | 数据库连接信息,格式为 用户名/密码@主机:端口 | SYSDBA/SYSDBA@127.0.0.1:5236 |

    | FILE | 导入文件名称,多个文件用逗号分隔 | dexp_full.dmp |

    | LOG | 日志文件名称 | dimp_full.log |

    | DIRECTORY | 导入文件所在目录路径 | /dm8/backup |

    | FULL | 是否全库导入,Y 表示是,N 表示否 | Y |

    | OWNER | 按用户导入,指定用户名列表 | USER1,USER2 |

    | SCHEMAS | 按模式导入,指定模式名列表 | SCH1,SCH2 |

    | TABLES | 按表导入,指定表名列表 | SCH1.TAB1,SCH1.TAB2 |

    | IGNORE | 导入出错时是否忽略继续,Y 或 N | Y |

    | ROWS | 是否导入数据行,Y 或 N | Y |

    | INDEXES | 是否导入索引,Y 或 N | Y |

    | CONSTRAINTS | 是否导入约束,Y 或 N | Y |

    | TRIGGERS | 是否导入触发器,Y 或 N | Y |

    | GRANTS | 是否导入权限,Y 或 N | Y |

    | STATISTICS | 是否导入统计信息,Y 或 N | Y |

    | TABLE_EXISTS_ACTION | 表已存在时的处理方式 (SKIP/APPEND/TRUNCATE/REPLACE) | REPLACE |

    | PARALLEL | 并行度,加速导入 | 4 |

    | FEEDBACK | 进度反馈间隔,单位为行数 | 10000 |

    重要提示: FULL、OWNER、SCHEMAS、TABLES 四个级别参数互斥,同一命令中只能指定其中一个。

    2.3 导入文件准备

    在执行 DM-dimp 逻辑导入前,需确保 dmp 文件已就位:

  • 文件完整性校验: 确认 dmp 文件在传输过程中未损坏,可通过文件大小与源端对比验证。
  • 文件权限检查: 确保运行 DM-dimp 的操作系统用户对 dmp 文件和日志目录具有读写权限。
  • 文件清单整理: 若导出时产生了多个 dmp 分片文件,需将所有分片文件放置在同一目录下。
  • 导出信息回顾: 查阅 dexp 导出时的日志文件,了解导出的级别、对象清单与字符集信息。
  • 三、DM-dimp 逻辑导入操作步骤

    3.1 启动 DM-dimp 工具

    DM-dimp 工具位于达梦数据库安装目录的 bin 子目录下。按照以下步骤启动工具:

  • 登录目标数据库所在服务器,切换至达梦数据库安装用户。
  • 进入 DM 安装目录的 bin 目录,例如 cd /dm8/bin。
  • 执行 ./dimp help 命令查看工具帮助信息,确认工具可用。
  • 准备好连接信息、文件路径等参数,为后续执行导入命令做准备。
  • 3.2 执行导入命令

    以下以模式级导入为例,演示 DM-dimp 逻辑导入的完整执行过程:

  • 基础命令格式:
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_schemas.dmp \\
    LOG=/dm8/backup/dimp_schemas.log \\
    DIRECTORY=/dm8/backup \\
    SCHEMAS=TEST_SCHEMA \\
    ROWS=Y \\
    INDEXES=Y \\
    CONSTRAINTS=Y \\
    TABLE_EXISTS_ACTION=REPLACE \\
    PARALLEL=4 \\
    FEEDBACK=10000

  • 参数解析:
    • USERID 指定以 SYSDBA 用户连接本机 5236 端口的数据库实例。
    • FILE 指定导入文件为 dexp_schemas.dmp。
    • LOG 指定日志输出文件为 dimp_schemas.log。
    • SCHEMAS 指定导入模式为 TEST_SCHEMA。
    • TABLE_EXISTS_ACTION 设为 REPLACE,表示目标表已存在时先删除再创建。
    • PARALLEL 设为 4,启用 4 线程并行导入。
  • 执行流程图:
  • #publish-mermaid-1786508095888-1{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-1786508095888-1 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786508095888-1 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786508095888-1 .error-icon{fill:#552222;}#publish-mermaid-1786508095888-1 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786508095888-1 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786508095888-1 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786508095888-1 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786508095888-1 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786508095888-1 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786508095888-1 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786508095888-1 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786508095888-1 .marker.cross{stroke:#333333;}#publish-mermaid-1786508095888-1 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786508095888-1 p{margin:0;}#publish-mermaid-1786508095888-1 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786508095888-1 .cluster-label text{fill:#333;}#publish-mermaid-1786508095888-1 .cluster-label span{color:#333;}#publish-mermaid-1786508095888-1 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786508095888-1 .label text,#publish-mermaid-1786508095888-1 span{fill:#333;color:#333;}#publish-mermaid-1786508095888-1 .node rect,#publish-mermaid-1786508095888-1 .node circle,#publish-mermaid-1786508095888-1 .node ellipse,#publish-mermaid-1786508095888-1 .node polygon,#publish-mermaid-1786508095888-1 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786508095888-1 .rough-node .label text,#publish-mermaid-1786508095888-1 .node .label text,#publish-mermaid-1786508095888-1 .image-shape .label,#publish-mermaid-1786508095888-1 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786508095888-1 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786508095888-1 .rough-node .label,#publish-mermaid-1786508095888-1 .node .label,#publish-mermaid-1786508095888-1 .image-shape .label,#publish-mermaid-1786508095888-1 .icon-shape .label{text-align:center;}#publish-mermaid-1786508095888-1 .node.clickable{cursor:pointer;}#publish-mermaid-1786508095888-1 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786508095888-1 .arrowheadPath{fill:#333333;}#publish-mermaid-1786508095888-1 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786508095888-1 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786508095888-1 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786508095888-1 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786508095888-1 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786508095888-1 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786508095888-1 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786508095888-1 .cluster text{fill:#333;}#publish-mermaid-1786508095888-1 .cluster span{color:#333;}#publish-mermaid-1786508095888-1 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#publish-mermaid-1786508095888-1 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786508095888-1 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786508095888-1 .icon-shape,#publish-mermaid-1786508095888-1 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786508095888-1 .icon-shape p,#publish-mermaid-1786508095888-1 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786508095888-1 .icon-shape .label rect,#publish-mermaid-1786508095888-1 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786508095888-1 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786508095888-1 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786508095888-1 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].node rect,#publish-mermaid-1786508095888-1 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786508095888-1 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095888-1 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508095888-1 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}否是否是

    启动 DM-dimp 工具

    解析命令行参数

    连接目标数据库

    连接是否成功

    输出错误信息并退出

    读取 dmp 文件头部信息

    文件格式是否兼容

    报错并退出

    按级别解析对象元数据

    创建或替换数据库对象

    导入数据行

    重建索引与约束

    导入触发器与权限

    导入统计信息

    生成导入日志

    导入完成

  • 执行结果观察: 命令执行后,终端会实时输出导入进度信息。重点关注以下内容:
    • 对象创建成功或失败的提示信息。
    • 数据行导入的进度反馈计数。
    • 索引重建与约束启用的状态记录。
    • 最终的导入统计摘要信息。

    3.3 导入结果验证

    DM-dimp 逻辑导入执行完毕后,需要从多个维度验证导入结果:

  • 日志文件检查: 打开 dimp 生成的日志文件,搜索 ERROR、WARN 关键字,排查导入过程中的异常记录。
  • 对象数量对比: 在目标库中查询导入的模式或表的对象数量,与源库进行比对。
  • 数据行数验证: 对关键表执行 SELECT COUNT(*) 查询,验证数据行数是否与源库一致。
  • 数据抽样校验: 随机抽取若干条记录,比对字段值是否正确。
  • 对象有效性检查: 查询无效对象视图,确认存储过程、视图、触发器等对象状态有效。
  • — 查询模式下的表对象数量
    SELECT COUNT(*) FROM ALL_TABLES WHERE OWNER = 'TEST_SCHEMA';
    — 查询无效对象
    SELECT OBJECT_NAME, OBJECT_TYPE, STATUS
    FROM ALL_OBJECTS
    WHERE OWNER = 'TEST_SCHEMA' AND STATUS != 'VALID';

    四、DM-dimp 逻辑导入进阶应用

    4.1 模式级导入

    模式级导入是 DM-dimp 逻辑导入最常用的级别之一,适用于按业务模块进行数据迁移的场景。

  • 基本模式导入: 使用 SCHEMAS 参数指定一个或多个模式名。
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_sch.dmp \\
    LOG=/dm8/backup/dimp_sch.log \\
    DIRECTORY=/dm8/backup \\
    SCHEMAS=HR_SALES,HR_FINANCE

  • 模式重映射导入: 使用 REMAP_SCHEMA 参数将源模式数据导入到目标库中不同名称的模式下。
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_sch.dmp \\
    LOG=/dm8/backup/dimp_sch.log \\
    DIRECTORY=/dm8/backup \\
    SCHEMAS=HR_SALES \\
    REMAP_SCHEMA=HR_SALES:HR_SALES_NEW

  • 排除特定对象的模式导入: 结合 EXCLUDE 参数排除不需要导入的对象类型或具体对象。
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_sch.dmp \\
    LOG=/dm8/backup/dimp_sch.log \\
    DIRECTORY=/dm8/backup \\
    SCHEMAS=HR_SALES \\
    EXCLUDE=INDEXES

    4.2 表级导入

    表级导入适用于精细化的数据迁移需求,只导入指定的表及其数据。

  • 单表导入: 使用 TABLES 参数指定需要导入的表名,格式为 模式名.表名。
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_tab.dmp \\
    LOG=/dm8/backup/dimp_tab.log \\
    DIRECTORY=/dm8/backup \\
    TABLES=HR_SALES.EMPLOYEES,HR_SALES.DEPARTMENTS

  • 仅导入表结构: 设置 ROWS=N,仅创建表结构而不导入数据。
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_tab.dmp \\
    LOG=/dm8/backup/dimp_tab.log \\
    DIRECTORY=/dm8/backup \\
    TABLES=HR_SALES.EMPLOYEES \\
    ROWS=N

  • 表已存在时的追加导入: 设置 TABLE_EXISTS_ACTION=APPEND,在已有表中追加数据。
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_tab.dmp \\
    LOG=/dm8/backup/dimp_tab.log \\
    DIRECTORY=/dm8/backup \\
    TABLES=HR_SALES.EMPLOYEES \\
    TABLE_EXISTS_ACTION=APPEND \\
    IGNORE=Y

    4.3 用户级导入与全库导入

    用户级导入

    用户级导入以数据库用户为单位,导入该用户下的所有对象和数据。

  • 单用户导入:
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_user.dmp \\
    LOG=/dm8/backup/dimp_user.log \\
    DIRECTORY=/dm8/backup \\
    OWNER=HR_USER

  • 多用户导入:
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_user.dmp \\
    LOG=/dm8/backup/dimp_user.log \\
    DIRECTORY=/dm8/backup \\
    OWNER=HR_USER,FIN_USER

    全库导入

    全库导入将 dmp 文件中的所有数据库对象导入到目标库,适用于整库迁移或灾备恢复场景。

  • 执行全库导入命令:
  • ./dimp USERID=SYSDBA/SYSDBA@127.0.0.1:5236 \\
    FILE=/dm8/backup/dexp_full.dmp \\
    LOG=/dm8/backup/dimp_full.log \\
    DIRECTORY=/dm8/backup \\
    FULL=Y \\
    PARALLEL=8

  • 全库导入注意事项:
    • 全库导入要求执行用户具有 DBA 权限。
    • 导入前需确认目标库中系统对象状态,避免与导入的系统对象产生冲突。
    • 全库导入耗时长,建议在业务低峰期执行。

    五、DM-dimp 逻辑导入常见问题与优化

    5.1 常见错误处理

    在 DM-dimp 逻辑导入过程中,可能遇到以下常见问题及处理方法:

  • 表空间不足错误:
    • 现象: 日志中出现 "表空间不足" 或 "无法扩展" 错误。
    • 处理: 为对应表空间增加数据文件或扩展现有数据文件大小。
  • 对象已存在错误:
    • 现象: 导入时报 "对象已存在" 错误。
    • 处理: 设置 TABLE_EXISTS_ACTION 参数为 REPLACE 或 TRUNCATE,或设置 IGNORE=Y 跳过错误。
  • 字符集不匹配错误:
    • 现象: 导入后中文数据显示乱码。
    • 处理: 检查源库与目标库字符集,必要时修改目标库字符集或使用字符集转换工具。
  • 权限不足错误:
    • 现象: 导入时报 "权限不足" 错误。
    • 处理: 为执行导入的用户授予相应权限,或使用具有 DBA 权限的用户执行导入。
  • 内存不足错误:
    • 现象: 导入大表时报内存不足错误。
    • 处理: 调整 dm.ini 中的 MEMORY_POOL、SORT_BUF_SIZE 等参数,或降低 PARALLEL 并行度。

    5.2 性能优化建议

    为提升 DM-dimp 逻辑导入的效率,可采取以下优化措施:

  • 合理设置并行度: 根据服务器 CPU 核数与内存资源,设置 PARALLEL 参数为 4 至 8,避免过度并行导致资源争用。
  • 关闭非必要对象导入: 在仅需数据迁移的场景下,设置 INDEXES=N、CONSTRAINTS=N、TRIGGERS=N,待数据导入完成后再批量创建。
  • 增大排序缓冲区: 在 dm.ini 中适当增大 SORT_BUF_SIZE 参数值,提升索引重建时的排序效率。
  • 批量提交优化: 通过设置 COMMIT 参数控制提交频率,减少事务提交次数。
  • 分时段分批次导入: 对于超大规模数据,可按模式或表分批次导入,降低单次导入的资源压力。
  • #publish-mermaid-1786508096004-2{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#publish-mermaid-1786508096004-2 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786508096004-2 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786508096004-2 .error-icon{fill:#552222;}#publish-mermaid-1786508096004-2 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786508096004-2 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786508096004-2 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786508096004-2 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786508096004-2 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786508096004-2 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786508096004-2 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786508096004-2 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786508096004-2 .marker.cross{stroke:#333333;}#publish-mermaid-1786508096004-2 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786508096004-2 p{margin:0;}#publish-mermaid-1786508096004-2 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786508096004-2 .cluster-label text{fill:#333;}#publish-mermaid-1786508096004-2 .cluster-label span{color:#333;}#publish-mermaid-1786508096004-2 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786508096004-2 .label text,#publish-mermaid-1786508096004-2 span{fill:#333;color:#333;}#publish-mermaid-1786508096004-2 .node rect,#publish-mermaid-1786508096004-2 .node circle,#publish-mermaid-1786508096004-2 .node ellipse,#publish-mermaid-1786508096004-2 .node polygon,#publish-mermaid-1786508096004-2 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786508096004-2 .rough-node .label text,#publish-mermaid-1786508096004-2 .node .label text,#publish-mermaid-1786508096004-2 .image-shape .label,#publish-mermaid-1786508096004-2 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786508096004-2 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786508096004-2 .rough-node .label,#publish-mermaid-1786508096004-2 .node .label,#publish-mermaid-1786508096004-2 .image-shape .label,#publish-mermaid-1786508096004-2 .icon-shape .label{text-align:center;}#publish-mermaid-1786508096004-2 .node.clickable{cursor:pointer;}#publish-mermaid-1786508096004-2 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786508096004-2 .arrowheadPath{fill:#333333;}#publish-mermaid-1786508096004-2 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786508096004-2 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786508096004-2 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786508096004-2 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786508096004-2 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786508096004-2 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786508096004-2 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786508096004-2 .cluster text{fill:#333;}#publish-mermaid-1786508096004-2 .cluster span{color:#333;}#publish-mermaid-1786508096004-2 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#publish-mermaid-1786508096004-2 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786508096004-2 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786508096004-2 .icon-shape,#publish-mermaid-1786508096004-2 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786508096004-2 .icon-shape p,#publish-mermaid-1786508096004-2 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786508096004-2 .icon-shape .label rect,#publish-mermaid-1786508096004-2 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786508096004-2 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786508096004-2 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786508096004-2 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].node rect,#publish-mermaid-1786508096004-2 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786508096004-2 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508096004-2 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786508096004-2 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

    DM-dimp 性能优化

    并行度优化

    对象导入控制

    内存参数调优

    提交频率控制

    分批导入策略

    PARALLEL 设为 4-8

    按需关闭索引/约束/触发器

    增大 SORT_BUF_SIZE

    合理设置 COMMIT 参数

    按模式或表分批执行

    5.3 最佳实践总结

    结合实际运维经验,DM-dimp 逻辑导入的最佳实践总结如下:

  • 导入前充分准备: 做好环境检查、空间评估、对象梳理等准备工作,避免导入过程中因环境问题中断。
  • 小规模测试验证: 在大规模导入前,先在测试环境进行小规模导入验证,确认参数配置正确无误。
  • 日志全程记录: 始终指定 LOG 参数生成导入日志,便于事后审计与问题排查。
  • 导入后全面验证: 从对象数量、数据行数、数据内容、对象状态等多维度验证导入结果。
  • 制定回滚方案: 在执行大规模导入前,制定数据回滚方案,确保异常情况下可快速恢复。
  • 定期演练: 将 DM-dimp 逻辑导入纳入日常运维演练计划,确保团队成员熟练掌握操作流程。
  • 赞(0)
    未经允许不得转载:网硕互联帮助中心 » DM-dimp 逻辑导入:达梦数据库数据迁移与恢复的核心利器
    分享到: 更多 (0)

    评论 抢沙发

    评论前必须登录!