Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jAEbe-0005XQ-Js for pgsql-general@arkaria.postgresql.org; Fri, 06 Mar 2020 15:09:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAEbc-0003RF-BR for pgsql-general@arkaria.postgresql.org; Fri, 06 Mar 2020 15:09:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jAEbb-0003R8-Vy for pgsql-general@lists.postgresql.org; Fri, 06 Mar 2020 15:09:40 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jAEbY-0004FE-H2 for pgsql-general@lists.postgresql.org; Fri, 06 Mar 2020 15:09:39 +0000 Received: by mail-wr1-x441.google.com with SMTP id v11so2744667wrm.9 for ; Fri, 06 Mar 2020 07:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ocado.com; s=google; h=reply-to:subject:to:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=9RsDw0yKKZIdcxpsllKRyIq3qv5KDvOHliWUnCtjd+o=; b=FeH1FQ08EndieimNJSQfZUpMyq4ecxN7SiaxJoTPc1fFSEErCicmaChOa5UHX675jo s6f+S1ObMhaKxgTdAq488Ewwp2kRWVEfuPTkSZ9Tw9PUWtv6ZbhSWjEwaj5VshLKwfZY WmbK7/kFKphg3Jlevm0mH9dbcmnXR7+Bs99FZ89KGLdKkHcpZKaGfLxOQ3szcDRxw3P0 42DH+W5fnP2vqhV6ZADKA53xSDspPKGcMpUr1sN0CWTDnYJfeEWUXlWLqhk+1dxRhndf 59eKStidp2n/+URQZ5oV84buFx+6ApZ0UJFN67V7jNqxQaWF6MpUHsPaGgqWorz79mdp t47g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language; bh=9RsDw0yKKZIdcxpsllKRyIq3qv5KDvOHliWUnCtjd+o=; b=ovw3JzCcOsv3cq9rD2pJvsv7yB+uC6lgsYl9q8yaKhAuGReLavIZfvAKycp630j7MS j8FLidF97/DTASyyQqpJZprPVqMAYDSCOOpi8HgLlqDa+IShIVFjNBfxz2ri+72rhiOC WhdIIuei/9Hj2xx1y+317MovHcNmgdAZ919briTF2XtJozqVKnMDZfSYycj/DCgDde2A 3bp2cF8/pwDFOUiZInBdVdC+Ksvu1mNIEu9FC6JeBfRs99zrHMPngYH36QHHucHokUXY zhb6ekFE38/CNYxe2jJufI2WmZhxM+q8iWH7L9o17MXnxiTW6ProgJokQpCafbn5elkC 3E8Q== X-Gm-Message-State: ANhLgQ1lQtO+9wcRAUpTbVcnvt7kmZU0p2DkNZUR05TiQcGR3Msps6Qv FI4ynCCyK7nIT6U8T6YMZzxnblm0Yb9KSgfaJEoQWWXAQSPbdDzOT3jz+BoUF2OMF5qsPLXHjqb mgPfzUA1RuWNId+7bz6H2FJe8kcELZEUjmwsY3yD79+KHERWZzzcHDLs6Kb5gEgwO953UinUpYd eC9hY0I25lOFzZ X-Google-Smtp-Source: ADFU+vvFvmG3IkB0C/L8s0x0++ZoLqpUtslTRaYGN8zVk1mYAVp7TVDo+km2pmEq32sW36qRb0VxlQ== X-Received: by 2002:adf:b189:: with SMTP id q9mr4441631wra.169.1583507374894; Fri, 06 Mar 2020 07:09:34 -0800 (PST) Received: from [10.62.12.18] ([91.206.0.63]) by smtp.gmail.com with ESMTPSA id j14sm49606985wrn.32.2020.03.06.07.09.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Mar 2020 07:09:34 -0800 (PST) Reply-To: f.venchiarutti@ocado.com Subject: Re: Limit transaction lifetime To: pgsql-general@lists.postgresql.org References: From: Fabio Ugo Venchiarutti Organization: Ocado Technology Message-ID: <6d6f34b6-c492-2e64-d43a-8be86b0d8a88@ocado.com> Date: Fri, 6 Mar 2020 15:09:33 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 ` 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.