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: Sun, 6 May 2018 15:46:10 -0700 (MST)
Message-ID: <1525646770300-0.post@n3.nabble.com> (raw)
In-Reply-To: <1525018491488-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>
	<1525018491488-0.post@n3.nabble.com>

Progress report on this subject:

1/ Some clarifications: 

What is expected here is to update pgss counters for ALL the queries that
have been executed,
taking into account queries finished in SUCCESS and thoses finised with
ERROR.

Main interest here is to catch queries that are cancelled or interrupted
by a timeout after a long running period, that could be hours in BI
reporting environments.

Errors during parsing are not catched, because there is no hook available
before parsing 
and because witout parse tree available, QueryId can not be calculated. 
This is not a problem yet because the objective is not to count errors.

There was a remark off-list saying that cummulating SUCCESS and ERROR
counters
for the same query, could be a problem for thoses monitoring AVG indicators 
(becomming smaller than the SUCCESS ones).

One proposal is to add a Boolean flag (success) in the key of pgss:

dbid, userid, queryid, success, calls, total_time, ...
1     1       123      t        100      100 000
1     1       123      f         10    1 000 000

  

2/ Modifying pgss_ExecutorRun (as suggested by Tom Lane) with:


	PG_CATCH();
	{
		/* Added part to get counters on errors */
	        EState       *estate;
        	if (queryDesc->totaltime && pgss_enabled())
        	{
            		estate = queryDesc->estate;
            		InstrStopNode(queryDesc->totaltime, estate->es_processed);
            		InstrEndLoop(queryDesc->totaltime);

			pgss_store(queryDesc->sourceText,
				   queryDesc->plannedstmt->queryId,
				   queryDesc->plannedstmt->stmt_location,
				   queryDesc->plannedstmt->stmt_len,
				   queryDesc->totaltime->total * 1000.0,	/* convert to msec */
				   queryDesc->estate->es_processed,
				   &queryDesc->totaltime->bufusage,
				   NULL);
	        }

		nested_level--;
		PG_RE_THROW();
	}
	PG_END_TRY();


permits to catch simple queries in pgss (to be enhanced for utility
statements, pl/pgsql, 
parallel queries, ...).
Would such a code have a chance to be validated ?

Feedback is welcome.
Regards
PAscal



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




view thread (10+ messages)  latest in thread

Message-ID: <1525646770300-0.post@n3.nabble.com>
Permalink:  ../1525646770300-0.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1525646770300-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: <1525646770300-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> <1525018491488-0.post@n3.nabble.com> <1525646770300-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