3 ms·
Due to the large per-row overhead in PostgreSQL tables you should probably investigate other ways to store the table data first if you are trying to preserve sp
by CuriousSkeptic 10y ago
Due to the large per-row overhead in PostgreSQL tables you should probably investigate other ways to store the table data first if you are trying to preserve space.
In one application I achieved a lot savings by transposing the time series, and meters, to columns (arrays also have some overhead, so go for columns) and manually partitioning along one axis to avoid storing one key. Perhaps not applicable in this case, but someone might find it useful, I had a more or less fixed set of meters and times.
Ex
CREATE TABLE reading_20160917 (
meter_pos int PRIMARY KEY,
"meter1 @ 00:00" smallint not null,
"meter1 @ 01:00" smallint not null,
...
"meter2 @ 00:00" boolean not null,
"meter2 @ 01:00" boolean not null,
...
"meter3 @ 00:00" pg_catalog.char not null,
"meter3 @ 01:00" pg_catalog.char not null,
...
);
```
Some meta-programming is required to make that manageable though but PostgreSQL is quite flexible in that regard, so with the proper set of views and functions you can have a more naïve view of the data for querying.
If that approach won't do I would look into foreign data wrappers, something like CitusDB perhaps, or just go for an actual time series store.
- tofflos 10y agoIn the end I did what you are suggesting but implemented it using the PostgreSQL ARRAY datatype. It was easy support with Hibernate and the data was usable for analytical queries. Disk usage dropped down to roughly 1 GB.