Dev News Daily ENDE

A PostgreSQL extension stores HDR histograms as a first-class type for exact percentiles

pg_hdr_histogram reached 1.0.0 on 26 October. It is a PostgreSQL extension that stores a full high-dynamic-range histogram as a first-class column type, so latency percentiles — p50, p99, p99.9 — are computed from the stored distribution rather than approximated from a handful of fixed buckets. The author, Vladimir Pavliv, puts the precision at roughly 0.1% relative error across six orders of magnitude. Crucially, two histograms merge losslessly, so you can roll up per-minute rows into an hour, or combine the same metric from many hosts, without the error that normally accumulates when you average percentiles. It builds on HdrHistogram_c, ships hdr_add and hdr_merge aggregates, is parallel-safe and marked trusted.

A PostgreSQL extension stores HDR histograms as a first-class type for exact percentiles
A PostgreSQL extension stores HDR histograms as a first-class type for exact percentiles — Dev News Daily

What it means

Averaging percentiles is one of the quiet sins of monitoring — you cannot take the mean of two p99 values and get anything meaningful, yet dashboards do it constantly. Keeping the histogram itself in the database, as a type that merges correctly, is the fix: the aggregate function does the right thing and the application stops lying about its tail. That it is marked trusted matters more than it sounds, because a trusted extension can be installed by a non-superuser, which is the difference between "available on managed Postgres" and "file a ticket". For anyone storing latency in Postgres instead of a dedicated metrics store, this is a small, sharp tool.

Written by Victoria Shinder.