TimescaleDB 写
x/timescaledbWrite组件:v0.37.0+写入 TimescaleDB(PostgreSQL)。目标表需已建为 hypertable,并包含 time 列。
需要额外引入扩展库: rulego-components-iot (opens new window)
# 数据落盘模型
TimescaleDB 是 schema-first 数据库,组件不负责建表:目标表名 = SeriesPoint 的 measurement(写入配置节 db 指定的 schema 下),需用户预建为 hypertable,且列结构须覆盖写入数据:
time列(TIMESTAMPTZ,hypertable 时间维度),纳秒时间戳自动换算;- 每个 tag key 一列(如
device_id TEXT); - 每个 field key 一列(如
temp DOUBLE PRECISION)。
CREATE TABLE public.device_data (time TIMESTAMPTZ NOT NULL, device_id TEXT, temp DOUBLE PRECISION);
SELECT create_hypertable('public.device_data', 'time', if_not_exists => TRUE);
1
2
2
# 配置
| 字段 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| dsn | string | PostgreSQL 连接串,例如 host=localhost port=5432 user=postgres dbname=ts sslmode=disable。支持 ref:// 复用同链连接 | 必填 |
| db | string | PostgreSQL schema 名,支持 ${msg.xx}/${metadata.xx} 模板 | 必填 |
| measurement | string | 测点表名(可选)。配置后可直接把采集点数组透视为 SeriesPoint,或把扁平 map/map 数组逐行转换为 SeriesPoint;留空则输入必须已经是 SeriesPoint | 空 |
| tags | array | 落盘索引维度,见下表 | 空 |
| fields | array | 落盘字段映射,见下表;留空=全量展开(采集点)或整行 map 作为 fields | 空 |
# tags
每一项为一个键值对:
| key | value |
|---|---|
| 索引维度名 | 索引值,支持 ${msg.xx} 模板 |
# fields
每一项为一个字段映射:
| key | source |
|---|---|
| 落盘字段名 | 采集点 name 或 map key;留空=全量展开 |
# 输入格式(msg.Data)
输入为 SeriesPoint JSON 数组(或单对象)。配置 measurement 后可接收 iot_points.Data 采集点数组自动透视,或扁平 map/map 数组逐行转换。SeriesPoint 结构同 x/tsdbWrite。
在 GitHub 上编辑此页 (opens new window)
上次更新: 2026/08/01, 05:05:14