TDengine 系统表 — information_schema 与 performance_schema 完整参考

分类:10.SQL 参考 | 篇章:07 系统表
在这里插入图片描述

适用版本:TDengine v3.x(v3.3.x / v3.4.x) | 最后更新:2026-07-21

TDengine 通过 information_schema 和 performance_schema 两个系统数据库暴露元数据和运行时统计。本文是这些系统表的完整速查。

系统数据库概览

内容
information_schema元数据(数据库/表/列/Tag 等定义)
performance_schema运行时统计(连接、查询、消费者)
log监控日志(视配置)

详细解析

1. information_schema 主要表

表速查:

  ins_dnodes          - 数据节点
  ins_mnodes          - 管理节点
  ins_qnodes          - 查询节点
  ins_snodes          - 流节点
  ins_cluster         - 集群信息
  ins_databases       - 数据库列表
  ins_functions       - 自定义函数
  ins_indexes         - 索引
  ins_stables         - 超级表
  ins_tables          - 所有表
  ins_tags            - Tag 信息
  ins_columns         - 列信息
  ins_users           - 用户
  ins_grants          - 权限
  ins_vgroups         - VGroup 列表
  ins_configs         - 配置项
  ins_subscriptions   - 订阅
  ins_streams         - 流计算
  ins_topics          - Topic
  ins_consumers       - 消费者
  ins_tsmas           - TSMA
  ins_wals            - WAL 信息

2. 常用查询:节点与集群

-- 集群信息
SELECT * FROM information_schema.ins_cluster;
-- 列:id, name, create_time

-- 数据节点
SELECT id, endpoint, status, vnodes, support_vnodes 
FROM information_schema.ins_dnodes;

-- 管理节点
SELECT id, endpoint, role, status 
FROM information_schema.ins_mnodes;

-- VGroup 详情
SELECT vgroup_id, db_name, tables, status, v1_dnode, v2_dnode, v3_dnode 
FROM information_schema.ins_vgroups;

3. 常用查询:数据库与表

-- 所有数据库
SELECT name, vgroups, replica, precision, keep, status 
FROM information_schema.ins_databases;

-- 超级表
SELECT stable_name, db_name, columns, tags, tables 
FROM information_schema.ins_stables 
WHERE db_name = 'power';

-- 所有表(子表 + 普通表)
SELECT table_name, db_name, type, stable_name, vgroup_id 
FROM information_schema.ins_tables 
WHERE db_name = 'power' 
LIMIT 100;

-- 列定义
SELECT col_name, col_type, col_length, col_precision 
FROM information_schema.ins_columns 
WHERE table_name = 'meters' AND db_name = 'power';

-- Tag 信息
SELECT tag_name, tag_type, tag_value 
FROM information_schema.ins_tags 
WHERE table_name = 'd001';

4. 常用查询:用户与权限

-- 用户列表
SELECT name, super, enable, create_time 
FROM information_schema.ins_users;

-- 权限授予
SELECT user_name, privilege, db_name, table_name 
FROM information_schema.ins_grants;

-- 等价:
SHOW USERS;
SHOW GRANTS;

5. performance_schema 主要表

表速查:

  perf_apps            - 应用连接
  perf_connections     - 当前连接
  perf_queries         - 当前运行的查询
  perf_consumers       - TMQ 消费者
  perf_subscriptions   - 订阅运行时状态
  perf_offsets         - 消费位点
  perf_trans           - 事务
  perf_stream_tasks    - 流计算任务

6. 常用查询:监控运行时

-- 当前连接
SELECT app_id, ip, port, user, last_access 
FROM performance_schema.perf_connections;

-- 应用统计
SELECT app_id, name, pid, ip, ins_count, query_count 
FROM performance_schema.perf_apps;

-- 当前查询
SELECT 
  conn_id, 
  query_id, 
  user, 
  ep, 
  exec_usec/1000 AS exec_ms, 
  sql 
FROM performance_schema.perf_queries 
ORDER BY exec_usec DESC 
LIMIT 20;

-- 消费者状态
SELECT 
  consumer_id, group_id, status, 
  topic_name, end_offset - committed_offset AS lag 
FROM performance_schema.perf_consumers;

-- 流计算任务状态
SELECT 
  stream_name, status, 
  source_db, target_db, target_table 
FROM performance_schema.perf_stream_tasks;

7. 监控实用 SQL

-- TOP 10 最大表(按行数)
SELECT db_name, table_name, ntables, rows 
FROM information_schema.ins_tables 
ORDER BY rows DESC 
LIMIT 10;

-- 各数据库的表统计
SELECT db_name, COUNT(*) AS table_count 
FROM information_schema.ins_tables 
GROUP BY db_name;

-- VGroup 负载均衡检查
SELECT vgroup_id, db_name, tables, status 
FROM information_schema.ins_vgroups 
ORDER BY tables DESC;

-- 慢查询识别
SELECT user, exec_usec/1000 AS ms, sql 
FROM performance_schema.perf_queries 
WHERE exec_usec > 1000000  -- > 1 秒
ORDER BY exec_usec DESC;

-- 消费者 Lag 监控
SELECT 
  group_id, topic_name, 
  SUM(end_offset - committed_offset) AS total_lag 
FROM performance_schema.perf_consumers 
GROUP BY group_id, topic_name;

8. SHOW 语句对照

-- 常用 SHOW(等价于查询系统表)
SHOW DATABASES;      -- = ins_databases
SHOW TABLES;         -- = ins_tables (当前库)
SHOW STABLES;        -- = ins_stables
SHOW VGROUPS;        -- = ins_vgroups
SHOW DNODES;         -- = ins_dnodes
SHOW MNODES;         -- = ins_mnodes
SHOW USERS;          -- = ins_users
SHOW GRANTS;         -- = ins_grants
SHOW CONNECTIONS;    -- = perf_connections
SHOW QUERIES;        -- = perf_queries
SHOW CONSUMERS;      -- = perf_consumers
SHOW STREAMS;        -- = ins_streams
SHOW TOPICS;         -- = ins_topics
SHOW INDEXES;        -- = ins_indexes
SHOW TSMAS;          -- = ins_tsmas
SHOW VARIABLES;      -- = ins_configs

代码示例

健康检查脚本

-- 1. 集群节点状态
SELECT 'DNodes' AS check_type, COUNT(*) AS total, 
       SUM(CASE WHEN status='ready' THEN 1 ELSE 0 END) AS healthy 
FROM information_schema.ins_dnodes;

-- 2. VGroup 健康
SELECT vgroup_id, db_name, status 
FROM information_schema.ins_vgroups 
WHERE status != 'ready';

-- 3. 当前活跃查询
SELECT COUNT(*) AS active_queries FROM performance_schema.perf_queries;

-- 4. 数据库表数量
SELECT name, ntables FROM information_schema.ins_databases;

容量规划

-- 各数据库大小估算
SELECT 
  name AS db_name,
  vgroups,
  replica,
  ntables 
FROM information_schema.ins_databases 
ORDER BY ntables DESC;

-- VGroup 分布
SELECT 
  v1_dnode AS dnode, 
  COUNT(*) AS vgroup_count 
FROM information_schema.ins_vgroups 
GROUP BY v1_dnode;

流计算与订阅监控

-- 流状态汇总
SELECT 
  status, 
  COUNT(*) AS count 
FROM information_schema.ins_streams 
GROUP BY status;

-- 消费者总 Lag
SELECT 
  group_id,
  COUNT(*) AS consumer_count,
  SUM(end_offset - committed_offset) AS total_lag,
  MAX(end_offset - committed_offset) AS max_lag 
FROM performance_schema.perf_consumers 
GROUP BY group_id;

性能考量

系统表查询特性

表类型查询性能
ins_databases极快(缓存)
ins_stables
ins_tables (大量子表)中(视基数)
ins_columns
ins_tags (大量子表)
perf_queries即时(运行时)

使用建议

  • 监控脚本:用 SHOW 简单 vs 系统表灵活
  • 大量子表场景:避免全表扫 ins_tables
  • 性能监控:定期采样 perf_queries 而非持续

FAQ

Q1: 系统表能 INSERT 吗?

不能。只读。修改需通过对应 DDL/管理命令。

Q2: SHOW 和系统表有什么区别?

SHOW 是预定义查询,输出固定。系统表可自由 WHERE/聚合,更灵活。

Q3: log 数据库怎么开启?

# taos.cfg
monitor 1
monitorInterval 30

重启后自动创建 log 库。

Q4: 跨集群查看节点?

只能本集群。跨集群需在管理工具中查看。

Q5: 系统表会随版本变化吗?

字段可能增加,向后兼容。具体看版本 Release Note。

参考

系统构架篇

数据模型

存储引擎

查询引擎

数据写入

数据订阅

预聚合

索引

SQL 语句

关于 TDengine

TDengine 专为物联网IoT平台、工业大数据平台设计。其中,TDengine TSDB 是一款高性能、分布式的时序数据库(Time Series Database),同时它还带有内建的缓存、流式计算、数据订阅等系统功能;TDengine IDMP 是一款AI原生工业数据管理平台,它通过树状层次结构建立数据目录,对数据进行标准化、情景化,并通过 AI 提供实时分析、可视化、事件管理与报警等功能。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TDengine (老段)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值