P1 logger is a tool designed to store meter data conforming to the [ESMR or DSMR (European / Dutch Smart Meter Requirements) standard](https://github.com/jvhaarst/DSMR-P1-telegram-reader/blob/master/documentation/Dutch%20Smart%20Meter%20Requirements%20v5.0.2%20Final%20P1.pdf) as efficiently as possible in a PostgreSQL database. Optionally, TimescaleDB is supported. The data can easily be retrieved using tools such as Grafana for visualisation and analysis.
Dt1, Dt2, Rt1, Rt2, G, F and Fl are cumulative meter readings. Therefore, they function as counters that can only go up. By making them pointers to int, they can be set to 'nil' whenever a reading has not changed. This way, they are logged as NULL in the database when no change has happened, saving storage capacity. As an added benefit, this makes data retrieval, visualisation and analysis more light-weight.
Typical P1 meters update gas consumption once per minute. Not saving intermittent values theoretically saves 4 bytes per value. An average month has 43,829.0639 minutes. 4*43,829.0639 = 175,316.26 bytes = 0.18 MB
For D1-3 and R1-3, either Dx or Rx will be active. Therefore, their storage requirements can be sliced in half, saving 3 * 10.52 = 42.08 MB. This is different for D and R, as these contain the sum of each phase and are reported simultaneously. Not saving failures when there is no change, will save around 10.52MB per month per metric, so an additional 21.04MB.
### Theoretical storage requirements for a DSMR5 meter with metrics emitted every second
| Column | Column size (bytes) | Per month (MB) | X | Total (MB)|
At the expense of having to create more complicated queries for analysis and visualisation, the optimisations save at least 103.97 MB or 1-137.99/241.96 = 43% in uncompressed storage space per month.
In practice, the storage requirements are lower than those mentioned in the aforementioned theoretical calculations. Over 8 months, I collected a database of 1.04GB of metrics. Using ZSTD with the default level 3, the database can be compressed to just 12.77% of this.
It is therefore recommended to use filesystems supporting compression, such as BTRFS. The P1 logger operating on a btrfs filesystem with compression enabled at default levels, can store the aforementioned 1.04GB of metrics in just 136MB of physical disk space. With the highest ZSTD compression level, 19, the 1.04GB database is stored in just 8.14% of its original size.