0

如果我每秒存储一次数据,数据库将快速增长。我需要更少的几周/几个月前的测量细节。一个平均值就足够了。我有 5 个传感器:风速、风向、温度、光和雨。我将如何设计我的数据库?

4

1 回答 1

0

Well, I'd design a table for the current data and then tables with aggregated data. Every once in a while (maybe a nighly/weekly/monthly run) I'd aggregate the data, write it to the tables and delete it from the current data.

I'd have exactly the same table (fields: measurement id, wind speed, wind direction, temperature, light and rain, timestamp) for each aggregation level I need.

  1. measurements_weekly
  2. measurements_daily_average
  3. measurements_weekly_average
  4. measurements_monthly_average
  5. measurements_yearly_average

This has several advantages: The data can be managed separately (Backup/detailed reports etc.). You just need one aggregation procedure for all aggregation levels and run it with different timespans and tables as arguments. Queries on any table and thus analysis will be fast and performant.

If you dislike the seemingly redundant structures, two tables can be enough as well: one for the measurements and one for the aggregated measurements, which must then include a timespan. But this approach will introduce complexity to your aggregation routines and any analysis, thus I would not use it.

于 2010-12-11T14:25:19.590 回答