query_histogram
query_histogram · Collects shared-memory histograms of statement and transaction runtimes through executor and utility hooks.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100489 | query_histogram | query_histogram | 1.1 | STAT | BSD-2-Clause | C |
Usage
Sources:
query_histogram 1.1 records cluster-wide histograms of statement and transaction duration in shared memory. It reports counts and accumulated time by duration bin, but does not retain query identity or text.
Preload and read histograms
Configure the library and collection parameters, then restart PostgreSQL:
Install the SQL objects and query the views:
query_histogram.bin_width is measured in milliseconds, and query_histogram.bin_count is capped at 1000. A zero bin count disables collection but leaves hooks installed. Dynamic mode permits runtime changes at the cost of additional shared-memory locking.
Sampling, resets, and overhead
Each sampled execution updates a shared segment protected by a System V semaphore. Start with a low query_histogram.sample_pct, benchmark representative concurrency, and remember that sampled counts are not exact totals. Bin boundaries also discard distribution detail, and the extension cannot identify which normalized statement caused a slow bin.
query_histogram_reset() clears shared observations for all users, so restrict execution and coordinate collectors before resetting. The SQL declares state-reading and reset functions IMMUTABLE even though their results depend on mutable shared state; do not rely on planner caching semantics around them. The source predates current PostgreSQL majors and publishes no current compatibility matrix, so compile and load-test the exact target version and every other executor-hook extension.