pg_hdr_histogram 1.0.0 Brings Exact Percentiles to PostgreSQL

PostgreSQL·26 Oct 2026·2 min read

#postgresql

Most monitoring stacks compute latency percentiles by counting samples into fixed buckets, which means the p99 you report is an approximation of the real distribution. pg_hdr_histogram 1.0.0, a new PostgreSQL extension by Vladimir Pavliv, takes a different route: it stores an entire HDR histogram as a first-class column type, so percentile queries return measurements rather than estimates. The project is built on HdrHistogram_c and advertises roughly 0.1% relative precision across 6 orders of magnitude.

Because the histogram is persisted as a native type, it can be queried, summed and combined directly in SQL. The headline capability is that histograms merge losslessly across time windows and even across hosts, which means rolling up per-instance latency into a single cluster-wide view does not degrade accuracy the way bucket aggregation does.

  • Adds an hdr histogram type stored as a first-class column, enabling p50, p99 and p99.9 queries with ~0.1% relative precision.
  • Provides the aggregates hdr_add and hdr_merge for combining histograms, both marked parallel-safe.
  • Ships as a trusted extension (trusted = true), so it can be installed by non-superusers with the right database privileges.
  • Built on the HdrHistogram_c library, following the well-known HdrHistogram design used across other language ecosystems.
  • Lossless merges mean histograms can be combined across time windows and hosts without approximation drift.

For developers running latency-sensitive services, this removes a longstanding trade-off between storage cost and percentile accuracy. Instead of pre-aggregating into buckets at write time and losing tail detail, you can keep the raw histogram in a table, merge it in parallel, and still answer tail-latency questions precisely later. That is particularly relevant for SLO reporting and post-incident analysis, where the difference between an estimate and a measurement can change the conclusion. The trade-off is that a histogram column carries more storage overhead than a counter, so teams will want to think about retention windows when adopting it.

Source: https://www.postgresql.org/about/news/pg_hdr_histogram-100-exact-percentiles-in-postgresql-3418/

Related

auto-curated · source linked above← all news