Resources · 91
Means and percentiles: aggregate without hiding slow tasks
Compare performance using consistent populations, units and time windows.
· 4 min
What this guide helps achieve
- Define the population
- Retain sums and counts
- Preserve distributions
- Document precision
- Read centre and tail together
- Separate empty groups and unknown values
Quick check
- Can p95 values be averaged?
- Why show counts?
- Should outliers be deleted?
Step-by-step method
- 01
Define the population
Specify received, completed or successful requests. Retain units, windows, filters and counts. Measure failures separately: excluding them can make an average misleadingly reassuring.
Output: Measurement contract and exclusions.
- 02
Retain sums and counts
For disjoint groups with the same scope, overall mean is the sum of values divided by their count. Weight group means by group counts; a simple average of means can distort the result.
Output: Count and sum table.
- 03
Preserve distributions
A percentile describes a position in a distribution. Averaging p95 values does not yield overall p95. Retain observations or compatible histograms that can be combined before estimation.
Output: Retained distribution with units.
- 04
Document precision
Record quantile method, bucket boundaries and estimation limits. Compare compatible instruments. Wide buckets may prevent distinguishing deterioration near an operational threshold.
Output: Estimation method and precision.
- 05
Read centre and tail together
Show counts, means and useful percentiles, then segment slow tasks. Inspect traffic and errors too. A changing mix of tasks can shift an overall metric without changing each task.
Output: Segmented interpretation tied to action.
- 06
Separate empty groups and unknown values
A zero count contributes no observations and does not define a zero mean. A missing mean in a non-empty group prevents aggregation. Also check that groups do not overlap: one request must not be counted in two batches.
Output: Missing-value and double-count checks.
Compare weighted group means
Combine disjoint batches measured in milliseconds using one definition. The fictional example yields 460 ms for 10 observations at 100 ms and 90 at 500 ms. No percentile can be inferred.
Formula: Σ(count × mean) / Σ(count). Empty groups are excluded. This calculator does not save or transmit your values.
Fictional acceptance-test scenarios
These proposed cases are not client observations. Adapt data, permissions and acceptance criteria to your authorised environment.
| Situation to exercise | Result to check | Evidence to retain |
|---|---|---|
| Two batches: a 100 ms mean over 10 observations and 200 ms over 90. | Check the weighted mean: (100 × 10 + 200 × 90) / 100 = 190 ms, not 150 ms. | Sums, counts, units and matching measurement scope. |
| Two services publish only their p95 values. | Do not report their average as a global p95; obtain compatible distributions or disclose the limitation. | Available observations or buckets and aggregation method. |
| The dashboard mixes successful requests with fast failures. | State the population and compare outcome states before claiming better latency. | Filters, states, window and counts for each population. |
| One group contains two observations but its mean is unknown; another group is genuinely empty. | Reject the unknown mean in the non-empty group; exclude the empty group without inventing a zero observation. | Counts, missing values, displayed error and included groups. |
Reusable worksheet
Complete with your authorised observations. These fields are a working template, not observed results.
| Field | Information to record |
|---|---|
| Measure | Event, unit, window and exclusions |
| Groups | Observation count and sum |
| Quantiles | Method, buckets and precision |
| Interpretation | Slow segments, errors and traffic |
Worked example
Illustrative situation
Fictional example: 10 requests average 100 ms and another 90 average 500 ms.
Decision and expected evidence
The simple mean of the two groups is 300 ms; the mean of all 100 observations is 460 ms. Neither group mean determines p95.
Distinguish the mechanisms
| Mechanism | Purpose | Check or limitation |
|---|---|---|
| Mean | Describe average cost | Sensitive to extreme observations |
| Median | Describe a central observation | Does not describe the slow tail |
| p95 | Inspect the distribution tail | Specify population and estimation |
Management indicators
| Indicator | What it measures | First action |
|---|---|---|
| Counts | Included observations | Reconcile exclusions |
| Slow tail | Percentile of the distribution | Reproduce affected tasks |
| Composition | Weight of each segment | Compare consistent populations |
Common pitfalls
- Sensitive to extreme observations
- Does not describe the slow tail
- Specify population and estimation
Frequently asked questions
Can p95 values be averaged?
Not to obtain overall p95. Combine compatible distributions, then calculate or estimate the percentile.
Why show counts?
They enable weighting, reveal small groups and explain changes in population composition.
Should outliers be deleted?
Only under a justified rule. Retain exclusions and check whether they represent real incidents.
Join cardinality, NULL and aggregates
Read the cardinality behind a published number
When a result combines sources, ask what one row represents and how keys were matched. An apparently correct sum can conceal two offsetting errors. Pair counts and identifier coverage provide additional evidence.
- Document population before and after joining.
- Do not infer causation from the total alone.
- Connect the metric definition to actual retained rows.
Inspect pairs and aggregates in the workshop →
PostgreSQL 18 · Table expressions · PostgreSQL 18 · documentation reviewed 2026-10-23
PostgreSQL 18 · Aggregate functions · PostgreSQL 18 · documentation reviewed 2026-10-23
PostgreSQL 18 · Comparison functions · PostgreSQL 18 · documentation reviewed 2026-10-23
Official references
References consulted: . The method and worksheet propose checks to adapt to your context; they do not constitute certification.
