一、DM SQL 日志文件概述
1.1 什么是 DM SQL 日志文件
DM SQL 日志文件是达梦数据库 (Dameng Database) 用于记录 SQL 语句执行情况的日志文件,又称为 svr 日志。它由 DM 数据库服务器在运行过程中生成,记录了客户端发送到数据库的所有或部分 SQL 语句,以及执行时长、影响行数、错误码等关键运行时信息。与其他数据库 (如 Oracle 的 trace 文件、MySQL 的 general log) 类似,DM SQL 日志文件是 DBA 进行故障排查、安全审计与性能优化的核心抓手。
1.2 DM SQL 日志文件的核心价值
DM SQL 日志文件在实际生产环境中具有不可替代的作用,主要体现在以下几个方面:
- 故障排查:当业务出现异常报错或慢响应时,可通过日志快速定位问题 SQL。
- 性能优化:通过分析 SQL 执行耗时,识别慢 SQL 并进行针对性优化。
- 安全审计:记录用户操作行为,满足合规审计要求。
- 行为回溯:在数据被误操作时,可通过日志还原操作过程。
- 容量评估:通过 SQL 频次与影响行数评估系统负载。
1.3 DM SQL 日志文件与其他日志的关系
DM 数据库提供了多种日志文件,它们各司其职,共同构成完整的日志体系:
#publish-mermaid-1786727336591-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-1786727336591-0 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336591-0 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336591-0 .error-icon{fill:#552222;}#publish-mermaid-1786727336591-0 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727336591-0 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727336591-0 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727336591-0 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727336591-0 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727336591-0 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727336591-0 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727336591-0 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727336591-0 .marker.cross{stroke:#333333;}#publish-mermaid-1786727336591-0 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727336591-0 p{margin:0;}#publish-mermaid-1786727336591-0 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727336591-0 .cluster-label text{fill:#333;}#publish-mermaid-1786727336591-0 .cluster-label span{color:#333;}#publish-mermaid-1786727336591-0 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727336591-0 .label text,#publish-mermaid-1786727336591-0 span{fill:#333;color:#333;}#publish-mermaid-1786727336591-0 .node rect,#publish-mermaid-1786727336591-0 .node circle,#publish-mermaid-1786727336591-0 .node ellipse,#publish-mermaid-1786727336591-0 .node polygon,#publish-mermaid-1786727336591-0 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336591-0 .rough-node .label text,#publish-mermaid-1786727336591-0 .node .label text,#publish-mermaid-1786727336591-0 .image-shape .label,#publish-mermaid-1786727336591-0 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727336591-0 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727336591-0 .rough-node .label,#publish-mermaid-1786727336591-0 .node .label,#publish-mermaid-1786727336591-0 .image-shape .label,#publish-mermaid-1786727336591-0 .icon-shape .label{text-align:center;}#publish-mermaid-1786727336591-0 .node.clickable{cursor:pointer;}#publish-mermaid-1786727336591-0 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727336591-0 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727336591-0 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727336591-0 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727336591-0 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336591-0 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336591-0 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336591-0 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727336591-0 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727336591-0 .cluster text{fill:#333;}#publish-mermaid-1786727336591-0 .cluster span{color:#333;}#publish-mermaid-1786727336591-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-1786727336591-0 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727336591-0 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727336591-0 .icon-shape,#publish-mermaid-1786727336591-0 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336591-0 .icon-shape p,#publish-mermaid-1786727336591-0 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727336591-0 .icon-shape .label rect,#publish-mermaid-1786727336591-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-1786727336591-0 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727336591-0 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727336591-0 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].node rect,#publish-mermaid-1786727336591-0 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727336591-0 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336591-0 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336591-0 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
DM 数据库日志体系
dm.ini 运行日志
SQL 日志文件 svr_log
重做日志 redo log
归档日志 archive log
数据库启动与运行状态
SQL 执行详情
事务持久化
redo 备份恢复
其中,dm.ini 运行日志侧重数据库自身运行状态,重做日志和归档日志用于事务持久化与备份恢复,而 DM SQL 日志文件则专注于 SQL 级别的执行记录,是本文讨论的核心对象。
二、DM SQL 日志文件的配置与开关
2.1 通过 dm.ini 参数开启 SQL 日志
DM SQL 日志文件的总开关由 dm.ini 参数 SVR_LOG 控制,该参数为静态参数,修改后需要重启数据库实例才能生效。开启步骤如下:
# dm.ini 关键配置
SVR_LOG = 1
2.2 sqllog.ini 配置详解
当 SVR_LOG = 1 后,DM 数据库会读取 sqllog.ini 文件来决定 SQL 日志的具体记录策略。sqllog.ini 通常与 dm.ini 位于同一目录下,典型配置如下:
# sqllog.ini
BUF_TOTAL_SIZE = 10240
BUF_SIZE = 1024
BUF_KEEP_CNT = 6
[SLOG_ALL]
FILE_PATH = ../log
PART_STOR = 0
SWITCH_MODE = 2
SWITCH_LIMIT = 512
ASYNC_FLUSH = 1
FILE_NUM = 10
ITEMS = 0
SQL_TRACE_MASK = 2:3
MIN_EXEC_TIME = 0
USER_MODE = 0
USERS =
2.3 关键参数说明
下表对 sqllog.ini 中的高频参数进行重点说明:
| 参数 | 含义 | 推荐值 |
| — | — | — |
| BUF_TOTAL_SIZE | 日志 buffer 总大小,影响写入性能 | 10240 或更大 |
| SWITCH_MODE | 日志切换模式,推荐按时间切换 | 2 |
| SWITCH_LIMIT | 切换上限,模式 2 时单位为分钟 | 60 |
| FILE_NUM | 保留的日志文件数量,超出后自动删除 | 10 至 30 |
| ASYNC_FLUSH | 异步刷新,建议 1 以降低业务影响 | 1 |
| MIN_EXEC_TIME | 最小执行时间阈值,用于只记录慢 SQL | 视场景而定 |
| SQL_TRACE_MASK | SQL 类型掩码,控制记录哪些类型 SQL | 2:3 |
| USERS | 指定用户过滤,多个用逗号分隔 | 按需配置 |
各参数协同工作的整体流程如下:
#publish-mermaid-1786727336670-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-1786727336670-1 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336670-1 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336670-1 .error-icon{fill:#552222;}#publish-mermaid-1786727336670-1 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727336670-1 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727336670-1 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727336670-1 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727336670-1 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727336670-1 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727336670-1 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727336670-1 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727336670-1 .marker.cross{stroke:#333333;}#publish-mermaid-1786727336670-1 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727336670-1 p{margin:0;}#publish-mermaid-1786727336670-1 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727336670-1 .cluster-label text{fill:#333;}#publish-mermaid-1786727336670-1 .cluster-label span{color:#333;}#publish-mermaid-1786727336670-1 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727336670-1 .label text,#publish-mermaid-1786727336670-1 span{fill:#333;color:#333;}#publish-mermaid-1786727336670-1 .node rect,#publish-mermaid-1786727336670-1 .node circle,#publish-mermaid-1786727336670-1 .node ellipse,#publish-mermaid-1786727336670-1 .node polygon,#publish-mermaid-1786727336670-1 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336670-1 .rough-node .label text,#publish-mermaid-1786727336670-1 .node .label text,#publish-mermaid-1786727336670-1 .image-shape .label,#publish-mermaid-1786727336670-1 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727336670-1 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727336670-1 .rough-node .label,#publish-mermaid-1786727336670-1 .node .label,#publish-mermaid-1786727336670-1 .image-shape .label,#publish-mermaid-1786727336670-1 .icon-shape .label{text-align:center;}#publish-mermaid-1786727336670-1 .node.clickable{cursor:pointer;}#publish-mermaid-1786727336670-1 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727336670-1 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727336670-1 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727336670-1 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727336670-1 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336670-1 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336670-1 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336670-1 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727336670-1 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727336670-1 .cluster text{fill:#333;}#publish-mermaid-1786727336670-1 .cluster span{color:#333;}#publish-mermaid-1786727336670-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-1786727336670-1 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727336670-1 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727336670-1 .icon-shape,#publish-mermaid-1786727336670-1 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336670-1 .icon-shape p,#publish-mermaid-1786727336670-1 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727336670-1 .icon-shape .label rect,#publish-mermaid-1786727336670-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-1786727336670-1 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727336670-1 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727336670-1 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].node rect,#publish-mermaid-1786727336670-1 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727336670-1 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336670-1 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336670-1 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}否是否是否是否是1 异步0 同步
SQL 到达服务器
SVR_LOG 是否开启
不记录
读取 sqllog.ini
SQL 类型是否命中掩码
是否满足 MIN_EXEC_TIME
用户是否在过滤范围
写入 buffer
ASYNC_FLUSH
后台线程刷新到文件
直接刷新到文件
三、DM SQL 日志文件的管理与运维
3.1 日志文件位置与命名规则
DM SQL 日志文件默认存放在 DM 安装目录下的 log 子目录中,文件命名遵循 dmsql_实例名_日期_时间.log 的规则。例如:
dmsql_DMSERVER_20240101_120000.log
当 SWITCH_MODE = 2 时,系统会按 SWITCH_LIMIT 指定的时间间隔自动切换日志文件,旧文件按 FILE_NUM 数量保留,超出部分会被自动清理。
3.2 日志切换与清理策略
合理的日志切换与清理策略既能保证日志可追溯,又能避免磁盘被撑满。整体策略流程如下:
#publish-mermaid-1786727336782-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-1786727336782-2 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336782-2 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336782-2 .error-icon{fill:#552222;}#publish-mermaid-1786727336782-2 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727336782-2 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727336782-2 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727336782-2 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727336782-2 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727336782-2 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727336782-2 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727336782-2 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727336782-2 .marker.cross{stroke:#333333;}#publish-mermaid-1786727336782-2 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727336782-2 p{margin:0;}#publish-mermaid-1786727336782-2 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727336782-2 .cluster-label text{fill:#333;}#publish-mermaid-1786727336782-2 .cluster-label span{color:#333;}#publish-mermaid-1786727336782-2 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727336782-2 .label text,#publish-mermaid-1786727336782-2 span{fill:#333;color:#333;}#publish-mermaid-1786727336782-2 .node rect,#publish-mermaid-1786727336782-2 .node circle,#publish-mermaid-1786727336782-2 .node ellipse,#publish-mermaid-1786727336782-2 .node polygon,#publish-mermaid-1786727336782-2 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336782-2 .rough-node .label text,#publish-mermaid-1786727336782-2 .node .label text,#publish-mermaid-1786727336782-2 .image-shape .label,#publish-mermaid-1786727336782-2 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727336782-2 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727336782-2 .rough-node .label,#publish-mermaid-1786727336782-2 .node .label,#publish-mermaid-1786727336782-2 .image-shape .label,#publish-mermaid-1786727336782-2 .icon-shape .label{text-align:center;}#publish-mermaid-1786727336782-2 .node.clickable{cursor:pointer;}#publish-mermaid-1786727336782-2 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727336782-2 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727336782-2 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727336782-2 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727336782-2 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336782-2 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336782-2 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336782-2 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727336782-2 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727336782-2 .cluster text{fill:#333;}#publish-mermaid-1786727336782-2 .cluster span{color:#333;}#publish-mermaid-1786727336782-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-1786727336782-2 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727336782-2 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727336782-2 .icon-shape,#publish-mermaid-1786727336782-2 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336782-2 .icon-shape p,#publish-mermaid-1786727336782-2 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727336782-2 .icon-shape .label rect,#publish-mermaid-1786727336782-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-1786727336782-2 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727336782-2 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727336782-2 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].node rect,#publish-mermaid-1786727336782-2 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727336782-2 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336782-2 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336782-2 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}按时间 SWITCH_LIMIT按大小 SWITCH_LIMIT是否
SQL 日志写入当前文件
达到切换条件
关闭当前文件
生成新日志文件
当前文件数大于 FILE_NUM
删除最旧文件
继续写入新文件
生产环境建议:
3.3 动态开启与关闭 SQL 日志
在生产环境中,有时需要临时开启 SQL 日志抓取问题,而不希望重启数据库。DM 提供了系统过程来动态控制 SQL 日志:
— 动态修改 SVR_LOG 参数
CALL SP_SET_PARA_VALUE(1, 'SVR_LOG', 1);
— 重新加载 sqllog.ini 配置
CALL SP_REFRESH_SVR_LOG_CONFIG();
— 关闭 SQL 日志
CALL SP_SET_PARA_VALUE(1, 'SVR_LOG', 0);
动态开关的执行流程:
#publish-mermaid-1786727336848-3{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-1786727336848-3 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336848-3 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336848-3 .error-icon{fill:#552222;}#publish-mermaid-1786727336848-3 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727336848-3 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727336848-3 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727336848-3 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727336848-3 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727336848-3 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727336848-3 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727336848-3 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727336848-3 .marker.cross{stroke:#333333;}#publish-mermaid-1786727336848-3 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727336848-3 p{margin:0;}#publish-mermaid-1786727336848-3 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727336848-3 .cluster-label text{fill:#333;}#publish-mermaid-1786727336848-3 .cluster-label span{color:#333;}#publish-mermaid-1786727336848-3 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727336848-3 .label text,#publish-mermaid-1786727336848-3 span{fill:#333;color:#333;}#publish-mermaid-1786727336848-3 .node rect,#publish-mermaid-1786727336848-3 .node circle,#publish-mermaid-1786727336848-3 .node ellipse,#publish-mermaid-1786727336848-3 .node polygon,#publish-mermaid-1786727336848-3 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336848-3 .rough-node .label text,#publish-mermaid-1786727336848-3 .node .label text,#publish-mermaid-1786727336848-3 .image-shape .label,#publish-mermaid-1786727336848-3 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727336848-3 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727336848-3 .rough-node .label,#publish-mermaid-1786727336848-3 .node .label,#publish-mermaid-1786727336848-3 .image-shape .label,#publish-mermaid-1786727336848-3 .icon-shape .label{text-align:center;}#publish-mermaid-1786727336848-3 .node.clickable{cursor:pointer;}#publish-mermaid-1786727336848-3 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727336848-3 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727336848-3 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727336848-3 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727336848-3 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336848-3 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336848-3 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336848-3 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727336848-3 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727336848-3 .cluster text{fill:#333;}#publish-mermaid-1786727336848-3 .cluster span{color:#333;}#publish-mermaid-1786727336848-3 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-1786727336848-3 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727336848-3 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727336848-3 .icon-shape,#publish-mermaid-1786727336848-3 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336848-3 .icon-shape p,#publish-mermaid-1786727336848-3 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727336848-3 .icon-shape .label rect,#publish-mermaid-1786727336848-3 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336848-3 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727336848-3 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727336848-3 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].node rect,#publish-mermaid-1786727336848-3 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727336848-3 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336848-3 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336848-3 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
DBA 调用系统过程
修改内存参数
立即生效
无需重启实例
继续对外提供服务
注意:动态修改仅在内存生效,若需持久化,仍需同步修改 dm.ini 和 sqllog.ini 文件,否则实例重启后配置会丢失。
四、DM SQL 日志文件的分析与应用
4.1 日志格式解析
DM SQL 日志文件采用文本格式存储,每条记录包含丰富的执行上下文。典型日志格式如下:
2024-01-01 12:00:00.123 [INFO] session[1234] user[SYSDBA] ip[192.168.1.100]
SQL: SELECT * FROM T1 WHERE ID = 1;
EXECTIME: 3(ms) ROWS: 1 ERRORCODE: 0
关键字段含义:
- 时间戳:精确到毫秒,用于分析执行顺序。
- session:会话 ID,用于关联同一会话的多条 SQL。
- user:执行用户,用于审计。
- ip:客户端 IP,用于定位来源。
- SQL:实际执行的 SQL 语句。
- EXECTIME:执行耗时,单位毫秒。
- ROWS:影响或返回的行数。
- ERRORCODE:错误码,0 表示成功。
4.2 慢 SQL 定位实战
慢 SQL 定位是 DM SQL 日志文件最常见的应用场景。利用 Linux 文本处理工具,可以快速筛选出耗时较高的 SQL:
# 提取所有 EXECTIME 大于 100ms 的日志行
grep "EXECTIME" dmsql_DMSERVER_*.log | awk -F'EXECTIME: ' '{print $2}' | awk -F'(ms)' '$1 > 100 {print}' | sort -nr | head -20
慢 SQL 定位分析流程:
#publish-mermaid-1786727336910-4{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-1786727336910-4 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336910-4 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336910-4 .error-icon{fill:#552222;}#publish-mermaid-1786727336910-4 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727336910-4 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727336910-4 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727336910-4 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727336910-4 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727336910-4 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727336910-4 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727336910-4 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727336910-4 .marker.cross{stroke:#333333;}#publish-mermaid-1786727336910-4 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727336910-4 p{margin:0;}#publish-mermaid-1786727336910-4 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727336910-4 .cluster-label text{fill:#333;}#publish-mermaid-1786727336910-4 .cluster-label span{color:#333;}#publish-mermaid-1786727336910-4 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727336910-4 .label text,#publish-mermaid-1786727336910-4 span{fill:#333;color:#333;}#publish-mermaid-1786727336910-4 .node rect,#publish-mermaid-1786727336910-4 .node circle,#publish-mermaid-1786727336910-4 .node ellipse,#publish-mermaid-1786727336910-4 .node polygon,#publish-mermaid-1786727336910-4 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336910-4 .rough-node .label text,#publish-mermaid-1786727336910-4 .node .label text,#publish-mermaid-1786727336910-4 .image-shape .label,#publish-mermaid-1786727336910-4 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727336910-4 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727336910-4 .rough-node .label,#publish-mermaid-1786727336910-4 .node .label,#publish-mermaid-1786727336910-4 .image-shape .label,#publish-mermaid-1786727336910-4 .icon-shape .label{text-align:center;}#publish-mermaid-1786727336910-4 .node.clickable{cursor:pointer;}#publish-mermaid-1786727336910-4 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727336910-4 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727336910-4 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727336910-4 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727336910-4 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336910-4 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336910-4 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336910-4 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727336910-4 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727336910-4 .cluster text{fill:#333;}#publish-mermaid-1786727336910-4 .cluster span{color:#333;}#publish-mermaid-1786727336910-4 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-1786727336910-4 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727336910-4 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727336910-4 .icon-shape,#publish-mermaid-1786727336910-4 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336910-4 .icon-shape p,#publish-mermaid-1786727336910-4 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727336910-4 .icon-shape .label rect,#publish-mermaid-1786727336910-4 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336910-4 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727336910-4 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727336910-4 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].node rect,#publish-mermaid-1786727336910-4 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727336910-4 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336910-4 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336910-4 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
收集 DM SQL 日志文件
按 EXECTIME 过滤
排序提取 Top N
关联 SQL 文本
执行计划分析
索引或统计信息或重写优化
验证优化效果
4.3 性能优化案例
某业务系统在高峰期出现接口超时,通过 DM SQL 日志文件定位到如下慢 SQL:
SQL: SELECT COUNT(*) FROM ORDER_DETAIL WHERE CREATE_TIME >= '2024-01-01';
EXECTIME: 3580(ms) ROWS: 1 ERRORCODE: 0
优化步骤:
#publish-mermaid-1786727336970-5{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-1786727336970-5 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336970-5 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727336970-5 .error-icon{fill:#552222;}#publish-mermaid-1786727336970-5 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727336970-5 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727336970-5 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727336970-5 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727336970-5 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727336970-5 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727336970-5 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727336970-5 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727336970-5 .marker.cross{stroke:#333333;}#publish-mermaid-1786727336970-5 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727336970-5 p{margin:0;}#publish-mermaid-1786727336970-5 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727336970-5 .cluster-label text{fill:#333;}#publish-mermaid-1786727336970-5 .cluster-label span{color:#333;}#publish-mermaid-1786727336970-5 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727336970-5 .label text,#publish-mermaid-1786727336970-5 span{fill:#333;color:#333;}#publish-mermaid-1786727336970-5 .node rect,#publish-mermaid-1786727336970-5 .node circle,#publish-mermaid-1786727336970-5 .node ellipse,#publish-mermaid-1786727336970-5 .node polygon,#publish-mermaid-1786727336970-5 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336970-5 .rough-node .label text,#publish-mermaid-1786727336970-5 .node .label text,#publish-mermaid-1786727336970-5 .image-shape .label,#publish-mermaid-1786727336970-5 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727336970-5 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727336970-5 .rough-node .label,#publish-mermaid-1786727336970-5 .node .label,#publish-mermaid-1786727336970-5 .image-shape .label,#publish-mermaid-1786727336970-5 .icon-shape .label{text-align:center;}#publish-mermaid-1786727336970-5 .node.clickable{cursor:pointer;}#publish-mermaid-1786727336970-5 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727336970-5 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727336970-5 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727336970-5 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727336970-5 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336970-5 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336970-5 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336970-5 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727336970-5 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727336970-5 .cluster text{fill:#333;}#publish-mermaid-1786727336970-5 .cluster span{color:#333;}#publish-mermaid-1786727336970-5 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-1786727336970-5 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727336970-5 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727336970-5 .icon-shape,#publish-mermaid-1786727336970-5 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727336970-5 .icon-shape p,#publish-mermaid-1786727336970-5 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727336970-5 .icon-shape .label rect,#publish-mermaid-1786727336970-5 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727336970-5 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727336970-5 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727336970-5 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].node rect,#publish-mermaid-1786727336970-5 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727336970-5 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336970-5 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727336970-5 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
SQL 耗时 3580ms
EXPLAIN 全表扫描
创建时间索引
更新统计信息
耗时降至 12ms
五、常见问题与最佳实践
5.1 性能影响评估
开启 DM SQL 日志文件会对数据库产生一定开销,主要体现在:
- 磁盘 I/O:日志写入占用磁盘吞吐。
- CPU 与内存:日志格式化与 buffer 管理。
- 锁竞争:高并发下日志写入可能成为瓶颈。
建议生产环境采用 ASYNC_FLUSH = 1 异步刷新,并合理设置 MIN_EXEC_TIME 只记录慢 SQL,以将性能影响降至最低。性能开销与配置关系如下图:
#publish-mermaid-1786727337018-6{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-1786727337018-6 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727337018-6 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727337018-6 .error-icon{fill:#552222;}#publish-mermaid-1786727337018-6 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727337018-6 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727337018-6 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727337018-6 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727337018-6 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727337018-6 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727337018-6 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727337018-6 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727337018-6 .marker.cross{stroke:#333333;}#publish-mermaid-1786727337018-6 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727337018-6 p{margin:0;}#publish-mermaid-1786727337018-6 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727337018-6 .cluster-label text{fill:#333;}#publish-mermaid-1786727337018-6 .cluster-label span{color:#333;}#publish-mermaid-1786727337018-6 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727337018-6 .label text,#publish-mermaid-1786727337018-6 span{fill:#333;color:#333;}#publish-mermaid-1786727337018-6 .node rect,#publish-mermaid-1786727337018-6 .node circle,#publish-mermaid-1786727337018-6 .node ellipse,#publish-mermaid-1786727337018-6 .node polygon,#publish-mermaid-1786727337018-6 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727337018-6 .rough-node .label text,#publish-mermaid-1786727337018-6 .node .label text,#publish-mermaid-1786727337018-6 .image-shape .label,#publish-mermaid-1786727337018-6 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727337018-6 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727337018-6 .rough-node .label,#publish-mermaid-1786727337018-6 .node .label,#publish-mermaid-1786727337018-6 .image-shape .label,#publish-mermaid-1786727337018-6 .icon-shape .label{text-align:center;}#publish-mermaid-1786727337018-6 .node.clickable{cursor:pointer;}#publish-mermaid-1786727337018-6 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727337018-6 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727337018-6 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727337018-6 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727337018-6 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727337018-6 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727337018-6 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727337018-6 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727337018-6 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727337018-6 .cluster text{fill:#333;}#publish-mermaid-1786727337018-6 .cluster span{color:#333;}#publish-mermaid-1786727337018-6 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-1786727337018-6 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727337018-6 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727337018-6 .icon-shape,#publish-mermaid-1786727337018-6 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727337018-6 .icon-shape p,#publish-mermaid-1786727337018-6 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727337018-6 .icon-shape .label rect,#publish-mermaid-1786727337018-6 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727337018-6 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727337018-6 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727337018-6 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].node rect,#publish-mermaid-1786727337018-6 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727337018-6 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337018-6 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337018-6 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}阈值大阈值小或 0
SQL 日志性能开销
同步刷新 ASYNC_FLUSH=0
异步刷新 ASYNC_FLUSH=1
高开销 业务感知明显
低开销 业务基本无感
MIN_EXEC_TIME 过滤
记录量少 开销小
记录量大 开销上升
5.2 常见问题排查
5.3 最佳实践建议
#publish-mermaid-1786727337080-7{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-1786727337080-7 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727337080-7 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#publish-mermaid-1786727337080-7 .error-icon{fill:#552222;}#publish-mermaid-1786727337080-7 .error-text{fill:#552222;stroke:#552222;}#publish-mermaid-1786727337080-7 .edge-thickness-normal{stroke-width:1px;}#publish-mermaid-1786727337080-7 .edge-thickness-thick{stroke-width:3.5px;}#publish-mermaid-1786727337080-7 .edge-pattern-solid{stroke-dasharray:0;}#publish-mermaid-1786727337080-7 .edge-thickness-invisible{stroke-width:0;fill:none;}#publish-mermaid-1786727337080-7 .edge-pattern-dashed{stroke-dasharray:3;}#publish-mermaid-1786727337080-7 .edge-pattern-dotted{stroke-dasharray:2;}#publish-mermaid-1786727337080-7 .marker{fill:#333333;stroke:#333333;}#publish-mermaid-1786727337080-7 .marker.cross{stroke:#333333;}#publish-mermaid-1786727337080-7 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#publish-mermaid-1786727337080-7 p{margin:0;}#publish-mermaid-1786727337080-7 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#publish-mermaid-1786727337080-7 .cluster-label text{fill:#333;}#publish-mermaid-1786727337080-7 .cluster-label span{color:#333;}#publish-mermaid-1786727337080-7 .cluster-label span p{background-color:transparent;}#publish-mermaid-1786727337080-7 .label text,#publish-mermaid-1786727337080-7 span{fill:#333;color:#333;}#publish-mermaid-1786727337080-7 .node rect,#publish-mermaid-1786727337080-7 .node circle,#publish-mermaid-1786727337080-7 .node ellipse,#publish-mermaid-1786727337080-7 .node polygon,#publish-mermaid-1786727337080-7 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727337080-7 .rough-node .label text,#publish-mermaid-1786727337080-7 .node .label text,#publish-mermaid-1786727337080-7 .image-shape .label,#publish-mermaid-1786727337080-7 .icon-shape .label{text-anchor:middle;}#publish-mermaid-1786727337080-7 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#publish-mermaid-1786727337080-7 .rough-node .label,#publish-mermaid-1786727337080-7 .node .label,#publish-mermaid-1786727337080-7 .image-shape .label,#publish-mermaid-1786727337080-7 .icon-shape .label{text-align:center;}#publish-mermaid-1786727337080-7 .node.clickable{cursor:pointer;}#publish-mermaid-1786727337080-7 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#publish-mermaid-1786727337080-7 .arrowheadPath{fill:#333333;}#publish-mermaid-1786727337080-7 .edgePath .path{stroke:#333333;stroke-width:1px;}#publish-mermaid-1786727337080-7 .flowchart-link{stroke:#333333;fill:none;}#publish-mermaid-1786727337080-7 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727337080-7 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#publish-mermaid-1786727337080-7 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727337080-7 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#publish-mermaid-1786727337080-7 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#publish-mermaid-1786727337080-7 .cluster text{fill:#333;}#publish-mermaid-1786727337080-7 .cluster span{color:#333;}#publish-mermaid-1786727337080-7 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-1786727337080-7 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#publish-mermaid-1786727337080-7 rect.text{fill:none;stroke-width:0;}#publish-mermaid-1786727337080-7 .icon-shape,#publish-mermaid-1786727337080-7 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#publish-mermaid-1786727337080-7 .icon-shape p,#publish-mermaid-1786727337080-7 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#publish-mermaid-1786727337080-7 .icon-shape .label rect,#publish-mermaid-1786727337080-7 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#publish-mermaid-1786727337080-7 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#publish-mermaid-1786727337080-7 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#publish-mermaid-1786727337080-7 .node .neo-node{stroke:#9370DB;}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].node rect,#publish-mermaid-1786727337080-7 [data-look=\”neo\”].cluster rect,#publish-mermaid-1786727337080-7 [data-look=\”neo\”].node polygon{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].swimlane.cluster rect{filter:none;}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].node path{stroke:#9370DB;stroke-width:1px;}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].node .outer-path{filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].node .neo-line path{stroke:#9370DB;filter:none;}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].node circle{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].node circle .state-start{fill:#000000;}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].icon-shape .icon{fill:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337080-7 [data-look=\”neo\”].icon-shape .icon-neo path{stroke:#9370DB;filter:drop-shadow(1px 2px 2px rgba(185, 185, 185, 1));}#publish-mermaid-1786727337080-7 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
DM SQL 日志文件最佳实践
配置层
运维层
分析层
异步刷新与慢 SQL 过滤
定时归档与磁盘告警
集中采集与可视化
稳定高效运行
通过以上配置与管理策略,DM SQL 日志文件将成为数据库运维排障与性能优化的得力助手,帮助 DBA 在复杂生产环境中快速定位问题、持续优化系统性能。



