- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Influx 来存储我们的时间序列数据。当它工作时很酷,然后大约一个月后,它停止工作,我不明白为什么。 (类似本期https://github.com/influxdb/influxdb/issues/1386)
也许有一天 Influx 会很棒,但现在我需要使用更稳定的东西。我在考虑Postgres。我们的数据来自许多传感器,每个传感器都有一个传感器 ID。所以我正在考虑按如下方式构建我们的数据:
(pk), sensorId(string), time(timestamp), 值(float)
Influx 是为时间序列数据构建的,因此它可能有一些内置的优化。我是否需要自己进行优化以使 Postgres 高效?更具体地说,我有以下问题:
Influx 具有“系列”的概念,并且创建新系列的成本很低。所以我为每个传感器都有一个单独的系列。我应该为每个传感器创建一个单独的 Postgres 表吗?
我应该如何设置索引以加快查询速度?一个典型的查询是:选择 sensor123 最近 3 天的所有数据。
我应该为时间列使用时间戳还是整数?
如何设置保留策略?例如。自动删除超过一周的数据。
Postgres 会横向扩展吗?我可以为数据复制和负载平衡设置 ec2 集群吗?
我可以在 Postgres 中进行缩减采样吗?我在一些文章中读到我可以使用 date_trunc。但似乎我无法将它 date_trunc 到特定的时间间隔,例如25 秒。
还有其他我遗漏的注意事项吗?
提前致谢!
更新将时间列存储为大整数比将其存储为时间戳更快。我做错了什么吗?
将其存储为时间戳:
postgres=# explain analyze select * from test where sensorid='sensor_0';
Bitmap Heap Scan on test (cost=3180.54..42349.98 rows=75352 width=25) (actual time=10.864..19.604 rows=51840 loops=1)
Recheck Cond: ((sensorid)::text = 'sensor_0'::text)
Heap Blocks: exact=382
-> Bitmap Index Scan on sensorindex (cost=0.00..3161.70 rows=75352 width=0) (actual time=10.794..10.794 rows=51840 loops=1)
Index Cond: ((sensorid)::text = 'sensor_0'::text)
Planning time: 0.118 ms
Execution time: 22.984 ms
postgres=# explain analyze select * from test where sensorid='sensor_0' and addedtime > to_timestamp(1430939804);
Bitmap Heap Scan on test (cost=2258.04..43170.41 rows=50486 width=25) (actual time=22.375..27.412 rows=34833 loops=1)
Recheck Cond: (((sensorid)::text = 'sensor_0'::text) AND (addedtime > '2015-05-06 15:16:44-04'::timestamp with time zone))
Heap Blocks: exact=257
-> Bitmap Index Scan on sensorindex (cost=0.00..2245.42 rows=50486 width=0) (actual time=22.313..22.313 rows=34833 loops=1)
Index Cond: (((sensorid)::text = 'sensor_0'::text) AND (addedtime > '2015-05-06 15:16:44-04'::timestamp with time zone))
Planning time: 0.362 ms
Execution time: 29.290 ms
将其存储为大整数:
postgres=# explain analyze select * from test where sensorid='sensor_0';
Bitmap Heap Scan on test (cost=3620.92..42810.47 rows=85724 width=25) (actual time=12.450..19.615 rows=51840 loops=1)
Recheck Cond: ((sensorid)::text = 'sensor_0'::text)
Heap Blocks: exact=382
-> Bitmap Index Scan on sensorindex (cost=0.00..3599.49 rows=85724 width=0) (actual time=12.359..12.359 rows=51840 loops=1)
Index Cond: ((sensorid)::text = 'sensor_0'::text)
Planning time: 0.130 ms
Execution time: 22.331 ms
postgres=# explain analyze select * from test where sensorid='sensor_0' and addedtime > 1430939804472;
Bitmap Heap Scan on test (cost=2346.57..43260.12 rows=52489 width=25) (actual time=10.113..14.780 rows=31839 loops=1)
Recheck Cond: (((sensorid)::text = 'sensor_0'::text) AND (addedtime > 1430939804472::bigint))
Heap Blocks: exact=235
-> Bitmap Index Scan on sensorindex (cost=0.00..2333.45 rows=52489 width=0) (actual time=10.059..10.059 rows=31839 loops=1)
Index Cond: (((sensorid)::text = 'sensor_0'::text) AND (addedtime > 1430939804472::bigint))
Planning time: 0.154 ms
Execution time: 16.589 ms
最佳答案
您不应该为每个传感器创建一个表。相反,您可以在表中添加一个字段来标识它属于哪个系列。您还可以有另一个表来描述有关该系列的其他属性。如果数据点可以属于多个系列,那么您将需要一个完全不同的结构。
对于您在 q2 中描述的查询,您的 recorded_at 列上的索引应该有效(time 是 sql 保留关键字,因此最好避免将其作为名称)
您应该使用 TIMESTAMP WITH TIME ZONE 作为您的时间数据类型。
保留由您决定。
Postgres 有多种分片/复制选项。这是一个很大的话题。
不确定我是否理解您对 #6 的目标,但我相信您能想出办法。
关于postgresql - 从 Influx 迁移到 Postgres,需要提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30020699/
先上网卡数据采集脚本,这个基本上是最大的坑,因为一些数据的类型不正确会导致no datapoint的错误,真是令人抓狂,注意其中几个key的值必须是int或者float类型,如果你不慎写成了stri
本文分享自华为云社区《Prometheus搭乘华为云GaussDB(for Influx):让监控数据更安全》,作者:高斯Influx官方博客。 背景 Prometheus 作为一个独立的开源项目,开
本文分享自华为云社区《华为云GaussDB(for Influx)揭秘第三期:解密GaussDB(for Influx)时序洞察》,作者: 高斯Influx官方博客。 背景 GaussDB(for I
本文分享自华为云社区《华为云GaussDB(for Influx)揭秘第九期:最佳实践之数据直方图》,作者:GaussDB 数据库。 1. 背景 随着5G和IOT的快速发展,面对爆发式增长的时序数
本文分享自华为云社区《华为云GaussDB(for Influx)揭秘第九期:最佳实践之数据直方图》,作者:GaussDB 数据库。 1. 背景 随着5G和IOT的快速发展,面对爆发式增长的时序数
本文分享自华为云社区《华为云GaussDB(for Influx)揭秘第八期:GaussDB(for Influx)与开源企业版性能对比》,作者:高斯Influx官方博客 。 “你们的数据库性能怎么样
本文分享自华为云社区《华为云GaussDB(for Influx)揭秘第七期:最佳实践之数据建模》,作者: GaussDB 数据库。 华为云GaussDB(for Influx)时序数据库面向工业物联
本文分享自华为云社区《华为云GaussDB(for Influx)揭密第六期:数据分级存储》,作者:高斯Influx官方博客 。 “只存储这些数据一年就要花费200多万?” 面对老板的质疑,小王又重新
我有一个通过 telegraf 收集的测量值。它具有以下结构: 名称:智能设备 fieldKey fieldType -------- --------- exit_status inte
我用Influx记录了一些串口数据,并展示了这些数据的报表。 我有这样的需求: 获取2017-05-11到2017-05-17时间07:00 AM到09:00 AM的值的总和。 在 mysql 中,这
我正在使用 sprigboot 和 influx 客户端:https://github.com/influxdata/influxdb-java 我面临一个问题,我试图从流入数据库获取指定列,但当我将
我正在 influx 中存储一些数据,令人困惑的是 influx 比 Mysql 慢 4-5 倍。我尝试通过在 mysql 中插入 10000 行然后在 influxdb 中插入来进行测试。统计数据如
**摘要:**GaussDB(for Influx)通过提供hint功能,在单时间线的查询场景下,性能有大幅度的提升,能有效满足客户某些特定场景的查询需求。 本文分享自华为云社区《华为云GaussDB
我正在我的 ubuntu 上安装 influxdb_2.0.9,我按照这里的说明操作: https://docs.influxdata.com/influxdb/v2.0/install/?t=Lin
使用 InfluxDB (v1.1),我需要获取特定键的最后一个条目时间戳。不管它存储的是哪个测量值,也不管它是哪个值。 设置很简单,我有三个测量值:location , network和 usage
我使用 Influx 来存储我们的时间序列数据。当它工作时很酷,然后大约一个月后,它停止工作,我不明白为什么。 (类似本期https://github.com/influxdb/influxdb/is
我已经创建了一个容器并为 influxdb 执行了它。现在,与以前的版本一样,我们可以通过使用 influx 命令进入 influx shell 来访问数据库。但是当我输入 influx 命令时,我得
我已经创建了一个容器并为 influxdb 执行了它。现在,与以前的版本一样,我们可以通过使用 influx 命令进入 influx shell 来访问数据库。但是当我输入 influx 命令时,我得
刚刚安装了tutumcloud/influxdb aws ecs 上的 docker 镜像,想知道如何以持久的方式在 docker 容器中启用 http 身份验证标志?添加用户可以关闭 http 身份
我是 InfluxDB 的新手。 我用时间序列数据填充了流入测量 我有以下测量点 time,host,interface,value 2/11/2019 12:03:08 AM,XYZ_test ,g
我是一名优秀的程序员,十分优秀!