pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: legrand legrand <legrand_legrand@hotmail.com>
To: pgsql-general@postgresql.org
Subject: Re: pg_stat_statements : how to catch non successfully finished statements ?
Date: Thu, 30 Apr 2020 14:30:23 -0700 (MST)
Message-ID: <1588282223588-0.post@n3.nabble.com> (raw)
In-Reply-To: <3099.1524949133@sss.pgh.pa.us>
References: <1524774265469-0.post@n3.nabble.com>
	<20180427114503.GA12829@zakirov.localdomain>
	<1524946656214-0.post@n3.nabble.com>
	<3099.1524949133@sss.pgh.pa.us>

Tom Lane-2 wrote
> legrand legrand &lt;

> legrand_legrand@

> &gt; writes:
>> So the only solution is to had queryId to ErrorData in this hook
>> or create a new hook fired on ERROR and containing queryId ?
> 
> I see no particular need for a new hook.  What's needed here is for
> pgss_ExecutorRun (and maybe some other existing functions in
> pg_stat_statements) to go ahead and record the statement when they catch
> an error thrown out of standard_ExecutorRun, rather than just updating
> the module's nested_level variable and re-throwing.
> 
> The hard part here is that you have to be really careful what you do in
> a PG_CATCH block, because the only thing you know for sure about the
> backend's state is that it's not good.  Catalog fetches are right out,
> and anything that might itself throw an error had best be avoided as
> well.  (Which, among other things, means that examining executor state
> would be a bad idea, and I'm not even sure you'd want to traverse the plan
> tree.)
> 
> I'm not convinced that it's practical for pg_stat_statements to make a new
> shared hashtable entry under those constraints.  But figuring out how to
> minimize the risks around that is the stumbling block, not lack of a hook.
> 
> 			regards, tom lane

As far as I have been testing this with *cancelled* queries (Cancel, 
pg_cancel_backend(), statement_timeout, ...), I haven't found any problem.
 
Would limiting the PG_CATCH block to thoses *cancelled* queries  
and *no other error*, be an alternate solution ?

If yes, is there a way to identify what was the reason of the error when 
entering the PG_CATCH block (and point me to any exemple) ?

Thanks in advance.

Regards
PAscal



--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html





view thread (10+ messages)  latest in thread

Message-ID: <1588282223588-0.post@n3.nabble.com>
Permalink:  ../1588282223588-0.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1588282223588-0.post@n3.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: legrand_legrand@hotmail.com
  Subject: Re: pg_stat_statements : how to catch non successfully finished statements ?
  In-Reply-To: <1588282223588-0.post@n3.nabble.com>
  References: <1524774265469-0.post@n3.nabble.com> <20180427114503.GA12829@zakirov.localdomain> <1524946656214-0.post@n3.nabble.com> <3099.1524949133@sss.pgh.pa.us> <1588282223588-0.post@n3.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox