pg_hdr_histogram 1.0.0 brings exact latency percentiles to PostgreSQL
The extension stores full HDR histograms as a native PostgreSQL type, enabling precise p50/p99/p99.9 measurements with ~0.1% relative precision across six orders of magnitude.
Summary
pg_hdr_histogram 1.0.0, a new PostgreSQL extension by Vladimir Pavliv, introduces exact-latency percentile calculations as a first-class database type. Unlike conventional monitoring tools that derive percentiles from fixed-width buckets and introduce estimation error, this extension stores complete HDR histograms directly in PostgreSQL, yielding precise measurements rather than approximations.
The extension is built on HdrHistogram_c and exposes parallel-safe aggregate functions hdr_add and hdr_merge, both marked trusted. Histograms can be merged losslessly across time windows and hosts, making the extension suitable for distributed systems that need accurate latency aggregation without the precision loss typical of pre-bucketed metrics pipelines.
Extension architecture and precision guarantees
- Native histogram type: Stores a full HDR histogram as a first-class PostgreSQL data type rather than pre-computed bucket counts, preserving the complete latency distribution.
- Precision envelope: Delivers approximately 0.1% relative precision across six orders of magnitude, a significant improvement over fixed-bucket approximations used by most monitoring stacks.
- Lossless merge semantics: The hdr_merge aggregate enables histograms from different time windows or hosts to be combined without information loss, supporting accurate global percentile computation from sharded or temporal data.
- Parallel-safe aggregates: Both hdr_add and hdr_merge are parallel-safe, allowing the extension to scale with PostgreSQL's parallel query infrastructure for large aggregation workloads.
- Trusted extension: Marked trusted = true, permitting installation by non-superusers in appropriately configured databases, lowering operational friction for teams with restricted privileges.
Why it matters
For database operators and SREs running PostgreSQL as a metrics or observability backend, pg_hdr_histogram eliminates a common source of percentile inaccuracy without requiring external time-series databases. The extension's lossless merge capability also benefits distributed architectures where latency data must be rolled up from multiple nodes or retention windows without the distortion introduced by bucket-based approximation schemes.
Original reference: www.postgresql.org →