Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jURw8-0008HL-IN for pgsql-general@arkaria.postgresql.org; Fri, 01 May 2020 09:26:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jURw7-0006Fg-AZ for pgsql-general@arkaria.postgresql.org; Fri, 01 May 2020 09:26:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jURw7-0006FY-2W for pgsql-general@lists.postgresql.org; Fri, 01 May 2020 09:26:23 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jURvz-0002Df-EX for pgsql-general@postgresql.org; Fri, 01 May 2020 09:26:21 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 716931D057189 for ; Fri, 1 May 2020 02:26:13 -0700 (MST) Date: Fri, 1 May 2020 02:26:13 -0700 (MST) From: legrand legrand To: pgsql-general@postgresql.org Message-ID: <1588325173462-0.post@n3.nabble.com> In-Reply-To: <23780.1588285608@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> <1588282223588-0.post@n3.nabble.com> <23780.1588285608@sss.pgh.pa.us> Subject: Re: pg_stat_statements : how to catch non successfully finished statements ? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tom Lane-2 wrote > legrand legrand < > legrand_legrand@ > > writes: >> Tom Lane-2 wrote >>> 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. > >> 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 ? > > I do not see that that would make one iota of difference to the risk that > the executor state tree is inconsistent at the instant the error is > thrown. You can't test your way to the conclusion that it's safe, either > (much less that it'd remain safe); your test cases surely haven't hit > every CHECK_FOR_INTERRUPTS call in the backend. > > regards, tom lane new try: Considering that executor state tree is limited to QueryDesc->estate, that would mean that rows processed can not be trusted, but that queryid, buffers and *duration* (that is the more important one) can still be used ? Knowing that shared hashtable entries are now (in pg13) created during planning time. There is no need to create a new one for execution error: just update counters (current ones or new columns like "errors" , "total_error_time", ... added to pg_stat_statements view). Is that better ? Regards PAscal -- Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html