Re: Limit transaction lifetime

From: Fabio Ugo Venchiarutti <f(dot)venchiarutti(at)ocado(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Limit transaction lifetime
Date: 2020-03-06 15:09:33
Message-ID: 6d6f34b6-c492-2e64-d43a-8be86b0d8a88@ocado.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 06/03/2020 14:24, Andrei Zhidenkov wrote:
> Is there a way to limit a transaction lifetime in PostgreSQL? I could
> use `idle_in_transaction_session_timeout` parameter but it applies only
> to IDLE transactions. However, I want to rollback any transaction that
> executes more than specified period of time.
>
> --
>
> With best regards, Andrei Zhidenkov.

If it's a single command you're trying to limit `SET statement_timeout
TO <whatever>` should do the trick.

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).

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.

--
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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ravi Krishna 2020-03-06 15:58:18 Re: Real application clustering in postgres.
Previous Message Laurenz Albe 2020-03-06 15:00:46 Re: How to allow users to create and modify tables only in their own schemas, but with generic table owner