Re: auto_explain sample rate - Mailing list pgsql-hackers

From Craig Ringer
Subject Re: auto_explain sample rate
Date
Msg-id CAMsr+YE11CUsa_8bV7odghKKPM3L+kWMyr-HZyrhGpk16OsX1g@mail.gmail.com
Whole thread Raw
In response to Re: auto_explain sample rate  (Craig Ringer <craig@2ndquadrant.com>)
Responses Re: auto_explain sample rate  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers


On 2 June 2015 at 15:07, Craig Ringer <craig@2ndquadrant.com> wrote:
On 29 May 2015 at 11:35, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Craig Ringer <craig@2ndquadrant.com> writes:
> It's sometimes desirable to collect auto_explain data with ANALYZE in order
> to track down hard-to-reproduce issues, but the performance impacts can be
> pretty hefty on the DB.

> I'm inclined to add a sample rate to auto_explain so that it can trigger
> only on x percent of queries,

That sounds reasonable ...

Cool, I'll cook that up then. Thanks for the sanity check.

OK, here we go.

To make sure it doesn't trigger on all backends at once, and to ensure it doesn't rely on a shared point of contention in shmem, this sets up a counter with a random value on each backend start.

Because it needs to either always run both the Start and End hooks, or run neither, this doesn't count nested statements for sampling purposes. So if you run my_huge_plpgsql_function() then either all its statements will be explained or none of them will. This only applies if nested statement explain is enabled. It's possible to get around this by adding a separate nested statement counter that's reset at each top level End hook, but it doesn't seem worthwhile.

The sample rate has no effect on ANALYZE, which remains enabled or disabled for all queries. I don't see any point adding a separate sample rate control to ANALYZE only some sub-proportion of EXPLAINed statements.

--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Tra
Attachment

pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: Re: [GENERAL] 9.4.1 -> 9.4.2 problem: could not access status of transaction 1
Next
From: Michael Paquier
Date:
Subject: Re: why does txid_current() assign new transaction-id?