Re: Adding percentile metrics to pg_stat_statements module

2019-11-01 Thread Igor Calabria
>
> That's not what I wrote. My point was that we *should* store the digests
> themselves, otherwise we just introduce additional errors into the
> estimates, because it discards the weights/frequencies.


Sorry. I meant to write "no reason to *not* store the digests"


Em sex, 1 de nov de 2019 às 11:17, Tomas Vondra <
tomas.von...@2ndquadrant.com> escreveu:

> On Fri, Nov 01, 2019 at 11:11:13AM -0300, Igor Calabria wrote:
> >Yeah, I agree that there's no reason to store the digests themselves and I
> >really liked the idea of it being optional.
>
> That's not what I wrote. My point was that we *should* store the digests
> themselves, otherwise we just introduce additional errors into the
> estimates, because it discards the weights/frequencies.
>
> >If it turns out that memory consumption on real workloads is small enough,
> >it could eventually be turned on by default.
> >
>
> Maybe, but it's not just about memory consumption. CPU matters too.
>
> regards
>
> --
> Tomas Vondra  http://www.2ndQuadrant.com
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>


Re: Adding percentile metrics to pg_stat_statements module

2019-11-01 Thread Igor Calabria
Yeah, I agree that there's no reason to store the digests themselves and I
really liked the idea of it being optional.
If it turns out that memory consumption on real workloads is small enough,
it could eventually be turned on by default.

I'll start working on patch

Em qui, 31 de out de 2019 às 16:32, Tomas Vondra <
tomas.von...@2ndquadrant.com> escreveu:

> On Thu, Oct 31, 2019 at 12:51:17PM -0300, Igor Calabria wrote:
> >Hi everyone,
> >
> >I was taking a look at pg_stat_statements module and noticed that it does
> >not collect any percentile metrics. I believe that It would be really
> handy
> >to have those available and I'd love to contribute with this feature.
> >
> >The basic idea is to accumulate the the query execution times using an
> >approximation structure like q-digest or t-digest and add those results to
> >the pg_stat_statements table as fixed columns. Something like this
> >
> >p90_time:
> >p95_time:
> >p99_time:
> >p70_time:
> >...
> >
> >Another solution is to persist de digest structure in a binary column and
> >use a function to extract the desired quantile ilke this SELECT
> >approx_quantile(digest_times, 0.99) FROM pg_stat_statements
> >
>
> IMO having some sort of CDF approximation (being a q-digest or t-digest)
> would be useful, although it'd probably need to be optional (mostly
> becuase of memory consumption).
>
> I don't see why we would not store the digests themselves. Storing just
> some selected percentiles would be pretty problematic due to losing a
> lot of information on restart. Also, pg_stat_statements is not a table
> but a view on in-memory hash table.
>
>
> regards
>
> --
> Tomas Vondra  http://www.2ndQuadrant.com
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>


Adding percentile metrics to pg_stat_statements module

2019-10-31 Thread Igor Calabria
Hi everyone,

I was taking a look at pg_stat_statements module and noticed that it does
not collect any percentile metrics. I believe that It would be really handy
to have those available and I'd love to contribute with this feature.

The basic idea is to accumulate the the query execution times using an
approximation structure like q-digest or t-digest and add those results to
the pg_stat_statements table as fixed columns. Something like this

p90_time:
p95_time:
p99_time:
p70_time:
...

Another solution is to persist de digest structure in a binary column and
use a function to extract the desired quantile ilke this SELECT
approx_quantile(digest_times, 0.99) FROM pg_stat_statements

What do you guys think?
Cheers,