欢迎光临
我们一直在努力

DM 查看数据库信息:掌握达梦数据库运维核心技能

一、达梦数据库概述与查看信息的重要性

1.1 DM 数据库简介

达梦数据库 (DM Database) 是武汉达梦数据库股份有限公司自主研发的新一代大型通用关系型数据库管理系统,具有高性能、高可用、高安全等特性,广泛应用于金融、电信、能源、政务等关键行业。作为国产数据库的标杆产品,DM 数据库兼容 SQL 标准语法,并提供丰富的系统视图和管理工具,方便运维人员进行数据库信息查看与管理。

1.2 查看数据库信息的应用场景

在实际运维过程中,DM 查看数据库信息是日常工作的基础环节,典型应用场景包括:

  • 性能诊断:通过查看会话、等待事件和锁信息定位性能瓶颈。
  • 容量规划:通过查看表空间使用情况评估存储需求。
  • 安全审计:通过查看用户权限和登录记录保障数据库安全。
  • 版本兼容性检查:在迁移升级前确认数据库版本和字符集。
  • 故障排查:通过查看数据库日志和参数状态快速定位异常。
  • 1.3 常用查看工具介绍

    DM 数据库提供多种信息查看工具,主要包括:

  • disql 命令行工具:DM 自带的 SQL 交互工具,适合服务器端操作。
  • DM 管理工具 (DM Manager):图形化管理客户端,支持可视化查看。
  • 系统视图:通过查询 SYS 模式下的视图获取元数据。
  • 动态性能视图:以 V$ 开头,反映数据库实时运行状态。
  • 控制台工具 dmcvt:用于查看和转换 DM 控制文件。
  • 二、DM 查看数据库信息的常用方法

    2.1 查看方式总览

    DM 数据库信息查看的整体流程如下图所示,运维人员可根据实际场景选择合适的方式:

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

    开始 DM 查看数据库信息

    选择查看方式

    disql 命令行

    DM 管理工具

    系统视图查询

    动态性能视图

    查看版本与实例

    图形化浏览对象

    查询元数据

    查看实时状态

    输出结果

    分析与诊断

    完成

    2.2 使用 disql 工具查看

    disql 是 DM 数据库最常用的命令行工具,使用方式如下:

  • 登录 disql:在命令行输入 disql username/password@host:port 即可连接数据库。
  • 查看数据库版本:执行 SELECT * FROM v$version; 可获取数据库版本信息。
  • 查看实例状态:执行 SELECT name, status$ FROM v$instance; 可查看实例运行状态。
  • disql 工具支持脚本执行和结果导出,是运维人员必备工具。

    2.3 通过系统视图查看元数据

    DM 数据库在 SYS 模式下提供大量系统视图,用于查看数据库元数据:

  • SYS.DBA_TABLES:查看所有表信息。
  • SYS.DBA_USERS:查看所有用户信息。
  • SYS.DBA_TABLESPACES:查看所有表空间信息。
  • SYS.DBA_DATA_FILES:查看数据文件信息。
  • 查询时需要具备相应的 DBA 权限或对应对象的查询权限。

    2.4 使用 DM 管理工具图形化查看

    DM 管理工具提供图形化界面,查看数据库信息更加直观:

  • 启动 DM 管理工具并连接到目标数据库。
  • 在左侧导航树展开 "数据库" 节点。
  • 选择 "表空间"、"用户"、"模式" 等节点查看详细信息。
  • 右键节点选择 "属性" 可查看更详细的配置信息。
  • 图形化方式适合新手用户,操作简单直观。

    2.5 通过动态性能视图查看运行状态

    动态性能视图以 V$ 开头,反映数据库实时运行状态,常用视图包括:

  • V$SESSION:查看当前会话信息。
  • V$LOCK:查看锁信息。
  • V$PARAMETER:查看参数配置。
  • V$PROCESS:查看进程信息。
  • V$SQLSTATS:查看 SQL 执行统计。
  • 这些视图数据来自内存,查询实时性高,是性能诊断的重要依据。

    三、DM 查看数据库信息的具体操作步骤

    3.1 操作流程总览

    DM 查看数据库信息的标准操作流程如下图所示,建议按步骤有序执行:

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

    连接数据库

    验证权限

    选择查看对象

    执行查询

    分析结果

    记录与归档

    输出巡检报告

    3.2 查看数据库基本参数

    查看数据库基本参数的步骤如下:

  • 使用 disql 连接数据库:disql SYSDBA/SYSDBA@localhost:5236
  • 查看数据库版本:SELECT banner FROM v$version;
  • 查看实例信息:SELECT name, instance_name, status$ FROM v$instance;
  • 查看数据库参数:SELECT name, value FROM v$parameter WHERE name LIKE '%PORT%';
  • 查看数据库启动时间:SELECT startup_time FROM v$instance;
  • 执行结果可帮助判断数据库版本、运行状态及关键参数配置。

    3.3 查看表空间信息

    查看表空间信息的具体步骤如下:

  • 查看所有表空间:SELECT tablespace_name, status FROM dba_tablespaces;
  • 查看表空间大小与使用率:
  • SELECT t.tablespace_name,
    ROUND(SUM(d.bytes) / 1024 / 1024, 2) AS total_mb,
    ROUND(SUM(d.bytes) / 1024 / 1024 – SUM(f.bytes) / 1024 / 1024, 2) AS used_mb,
    ROUND((1 – SUM(f.bytes) / SUM(d.bytes)) * 100, 2) AS used_pct
    FROM dba_tablespaces t,
    dba_data_files d,
    (SELECT tablespace_name, SUM(bytes) bytes FROM dba_free_space GROUP BY tablespace_name) f
    WHERE t.tablespace_name = d.tablespace_name
    AND d.tablespace_name = f.tablespace_name
    GROUP BY t.tablespace_name;

  • 查看数据文件:SELECT file_name, bytes / 1024 / 1024 AS size_mb FROM dba_data_files;
  • 查看临时表空间:SELECT * FROM dba_temp_files;
  • 通过上述查询可全面了解表空间使用情况,为容量规划提供依据。

    3.4 查看用户与权限信息

    查看用户与权限信息的步骤如下:

  • 查看所有用户:SELECT username, account_status, created FROM dba_users;
  • 查看用户默认表空间:SELECT username, default_tablespace, temporary_tablespace FROM dba_users;
  • 查看用户系统权限:SELECT grantee, privilege FROM dba_sys_privs WHERE grantee = 'SYSDBA';
  • 查看用户对象权限:SELECT grantee, owner, table_name, privilege FROM dba_tab_privs WHERE grantee = 'TEST';
  • 查看角色信息:SELECT role FROM dba_roles;
  • 权限信息查看是数据库安全审计的重要环节。

    3.5 查看会话与锁信息

    查看会话与锁信息的步骤如下:

  • 查看当前会话:SELECT sid, serial#, username, status, machine FROM v$session;
  • 查看活动会话:SELECT sid, username, sql_text FROM v$session WHERE status = 'ACTIVE';
  • 查看锁信息:SELECT * FROM v$lock WHERE blocked = 1;
  • 查看等待事件:SELECT event, total_waits, time_waited FROM v$system_event ORDER BY time_waited DESC;
  • 查看 SQL 执行统计:SELECT sql_text, executions, elapsed_time FROM v$sqlstats ORDER BY elapsed_time DESC;
  • 通过分析会话和锁信息,可有效定位性能瓶颈和死锁问题。

    3.6 查看版本与字符集信息

    查看版本与字符集信息步骤如下:

  • 查看数据库版本:SELECT * FROM v$version;
  • 查看字符集:SELECT sf_get_para_value(1, 'CHARSET');
  • 查看大小写敏感:SELECT sf_get_case_sensitive_flag();
  • 查看兼容模式:SELECT sf_get_para_value(1, 'COMPATIBLE_MODE');
  • 查看数据库唯一标识:SELECT dbid, name FROM v$database;
  • 版本与字符集信息在数据库迁移、应用兼容性测试中尤为重要。

    四、常见问题与优化建议

    4.1 查看权限不足问题

    当查询系统视图时出现 "无权限" 错误,可采取以下解决方案:

  • 使用 SYSDBA 账户登录,具备最高权限。
  • 为普通用户授予查询权限:GRANT SELECT ON sys.dba_users TO test_user;
  • 使用 SYSAUDITOR 角色查看审计相关信息。
  • 创建只读运维账户,仅授予必要的查询权限。
  • 权限管理应遵循最小化原则,避免过度授权。

    4.2 查询性能优化

    查看数据库信息时,部分视图查询可能较慢,优化建议如下:

  • 加上 WHERE 条件限制返回行数,避免全表扫描。
  • 使用 ROWNUM 限制返回结果数量:SELECT * FROM v$session WHERE ROWNUM <= 20;
  • 在非业务高峰期执行大查询,减少对生产业务的影响。
  • 对常用查询结果进行缓存或定期归档。
  • 避免频繁查询动态性能视图,以免增加系统负载。
  • 4.3 信息查看的注意事项

    进行 DM 查看数据库信息时,应注意以下几点:

  • 避免在业务高峰期执行复杂查询,防止影响生产性能。
  • 重要操作前先确认当前连接的实例和数据库,避免误操作。
  • 查询结果建议保存到日志文件,便于后续分析对比。
  • 对敏感信息 (如密码哈希) 做脱敏处理后再记录。
  • 定期备份查询脚本和巡检结果,形成数据库运维知识库。
  • 升级数据库版本后,重新验证查询脚本的兼容性。
  • 赞(0)
    未经允许不得转载:171主机测评 » DM 查看数据库信息:掌握达梦数据库运维核心技能
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址