Summary
I am stuck on a problem where the row limit on a Materialized View is exceeding the maximum allowed in a Postgres Database.
Description
The table named PAC4200_Metering
has 108 fields that are all double precision fields. I would like to store a materialized cache of the tables where I store a JSON object with keys for average, max, min, etc of the field during the time bucket.
SELECT
"deviceId",
time_bucket('1 hours', "time") as starttime,
json_build_object(
'average', avg("voltage_an"),
'maxvalue', max("voltage_an"),
'minvalue', min("voltage_an"),
'sum', sum("voltage_an"),
'firstvalue', first("voltage_an", "time"),
'firsttime', min("time" AT TIME ZONE 'UTC'),
'lasttime', max("time" AT TIME ZONE 'UTC'),
'lastvalue', last("voltage_an", "time"),
'sd', stddev_pop("voltage_an") ,
'countgood', COUNT(*),
'countbad', 0,
'countuncertain', 0
) AS "voltage_an"
...
FROM
"PAC4200_Metering"
GROUP BY
"deviceId",
starttime
Error Response:
INFO: new materialization range for public.PAC4200_Metering larger than allowed in one run, truncating (time column time) (1568760300000000)
INFO: new materialization range for public.PAC4200_Metering (time column time) (1568708100000000)
INFO: materializing continuous aggregate public.PAC4200_Metering_15_minute: new range up to 1568708100000000
ERROR: row is too big: size 12456, maximum size 8160
CONTEXT: SQL statement "INSERT INTO _timescaledb_internal._materialized_hypertable_1108 SELECT * FROM _timescaledb_internal._partial_view_1108 AS I WHERE I.starttime >= '-infinity' AND I.starttime < '2019-09-17 08:15:00+00';"
SQL state: 54000
Alternative Methods I have Tried
Instead of populating as JSON objects, I have tried storing each key in the JSON object (average, min, max, etc...) as fields that look like this "voltage_an_avg", "voltage_an_min", "voltage_an_max" and then accessing them in this way, but I am still running into the same limitation.
Main Question / Solutions
- Is there a way to increase this row size limit? (if that is even good practice)
- Is there a better way to store these values...