pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fabio Ugo Venchiarutti <f.venchiarutti@ocado.com>
To: Andrei Zhidenkov <andrei.zhidenkov@n26.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Limit transaction lifetime
Date: Fri, 6 Mar 2020 16:18:53 +0000
Message-ID: <a91d84af-34da-c1e1-4324-b482dbc015a6@ocado.com> (raw)
In-Reply-To: <ED3B8A6F-1F2B-4833-B34E-5D99A050D9A6@n26.com>
References: <CAKtDQ6Bq424Rsk_AwdQ5vEXncDYzx184LnZ5R=xNiv1htAPKwQ@mail.gmail.com>
	<6d6f34b6-c492-2e64-d43a-8be86b0d8a88@ocado.com>
	<ED3B8A6F-1F2B-4833-B34E-5D99A050D9A6@n26.com>

On 06/03/2020 16:14, Andrei Zhidenkov wrote:
> 
>> If it's a single command you're trying to limit `SET statement_timeout TO <whatever>` should do the trick.
> 
> This will set only statement timeout but won’t work for long transactions that contain a lot of short statements.
> 
>> If you want it based on the session's cumulative statement time, off the top of my head I can't think of anything in vanilla PG without using executor hooks (that requires some coding).
> 
> Yes, that’s exactly I want to do.
> 
>> If the queries that worry you are long-lived, you might be able to get by with a scheduled process checking against pg_stat_activity (eg: age(query_start)) and adding the current query's run-time to some per-session total, but it's an highly inaccurate process.
> 
> I think in my case I should check `xact_start`, because not every query initiates a new transaction.
That way you'd also be counting in time a given transaction spent 
idling, which IME is one of the biggest source of concurrency headaches 
if it's holding locks while doing nothing.
If your use case is unaffected by that, that'd be good news for you.





-- 
Regards

Fabio Ugo Venchiarutti
OSPCFC Network Engineering Dpt.
Ocado Technology

-- 


Notice: 
This email is confidential and may contain copyright material of 
members of the Ocado Group. Opinions and views expressed in this message 
may not necessarily reflect the opinions and views of the members of the 
Ocado Group.

If you are not the intended recipient, please notify us 
immediately and delete all copies of this message. Please note that it is 
your responsibility to scan this message for viruses.

References to the 
"Ocado Group" are to Ocado Group plc (registered in England and Wales with 
number 7098618) and its subsidiary undertakings (as that expression is 
defined in the Companies Act 2006) from time to time. The registered office 
of Ocado Group plc is Buildings One & Two, Trident Place, Mosquito Way, 
Hatfield, Hertfordshire, AL10 9UL.





view thread (4+ messages)

Message-ID: <a91d84af-34da-c1e1-4324-b482dbc015a6@ocado.com>
Permalink:  ../a91d84af-34da-c1e1-4324-b482dbc015a6@ocado.com/
Also on:    postgresql.org/message-id/a91d84af-34da-c1e1-4324-b482dbc015a6@ocado.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: f.venchiarutti@ocado.com, andrei.zhidenkov@n26.com
  Subject: Re: Limit transaction lifetime
  In-Reply-To: <a91d84af-34da-c1e1-4324-b482dbc015a6@ocado.com>
  References: <CAKtDQ6Bq424Rsk_AwdQ5vEXncDYzx184LnZ5R=xNiv1htAPKwQ@mail.gmail.com> <6d6f34b6-c492-2e64-d43a-8be86b0d8a88@ocado.com> <ED3B8A6F-1F2B-4833-B34E-5D99A050D9A6@n26.com> <a91d84af-34da-c1e1-4324-b482dbc015a6@ocado.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