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 1jAFgj-0007uv-2m for pgsql-general@arkaria.postgresql.org; Fri, 06 Mar 2020 16:19:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAFgh-0000ED-RL for pgsql-general@arkaria.postgresql.org; Fri, 06 Mar 2020 16:18:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jAFgg-0000E6-Lf for pgsql-general@lists.postgresql.org; Fri, 06 Mar 2020 16:18:58 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jAFge-0003Lf-4e for pgsql-general@lists.postgresql.org; Fri, 06 Mar 2020 16:18:57 +0000 Received: by mail-wr1-x42e.google.com with SMTP id n7so3021934wrt.11 for ; Fri, 06 Mar 2020 08:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ocado.com; s=google; h=reply-to:subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kNeakG7SXkczEHXmhMo1eTB2fTuBt+fwE97cV3BuYBk=; b=0uAaeDHQWhDLJph52VlTo6svufbZGsf7ZvMTjLuZuHpZ6oznOqFSVvtKrcyxhpu4jK rA9dm8d3Hne1JbPYV2BJ20OP8BMYWHqgfpkXyVioXWf4bAfE5zGM4p9obLS6bntYY74v iZjJKo1YKekJlXxg+CwsXXVN+XE++5u4M+ptTc68AA5gHoMkF23vg3dMk2Rw6VtTPrgN P/i8WriWUyOkVMiiiP3GXLi/UeOSFbDn5YX5/iaSpsL0H1mkvcM6ABmsRCdymuSJRsGL RUcGOqPCfgSz3eDJK9VB35uIx6Kw1T49Ny7MgvwlVWN8nWNrYuhbcBSzzzE8eJ+CeoRp a/lQ== 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:cc:references:from :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=kNeakG7SXkczEHXmhMo1eTB2fTuBt+fwE97cV3BuYBk=; b=gjLmN0RgnHlKabfIKBC/ZaYNaq2svE0zru4hi5B/tfTWgWK87pyad2/EwE92LNyLLR nMbX2dznepKioQLFe1YUD++ruRzOibKhyTy6a7tGPC1rDHFLh+zuNcEVypXNIK+C7Zsv nLXduCSJScL0Tk4D6vdnxew9p5kaKXsnRxClNXCJMtdpbM1k9QcCmmP/zl+vMqgMf67X Rfyt3vOq6AQsqQGjJphTnb+nZWsbmg+R4JPcK2lPBQJ4znU9h6/zt5V+hXUmcFBmJbeY dNwc2Xz49YfUy9skOimW7ApgAKKYCDqJTAJce8ETBYx7AmMPHCN7CmmLLpazbIeqDHP2 fNeA== X-Gm-Message-State: ANhLgQ0pajbBNAjrQ9iYI2GpAAAVimD0HC/w4yGN4dlewBIkJJ/zM3Fy Qt2d1zCFGU/4sksEqzeI2UAYF/YCZ3V+VRLwJR5wsPLmihUAfrG5haFTaO+whieL5VY3c/RH65l RCPmUfRqZV6j+d1hC8eGBS423J+0Xg5T9NY8UFPMLZlYHLDOLH1wNhAcN5t7IdDf5KrvnWJ+C3R pMw2bkf21CM1jD X-Google-Smtp-Source: ADFU+vuYHMBDMRyF6bJFgsgMim8hgu5Lc0gNoFBjhRjOXU5M+4KzM0MW2cFZn9+aX/OedbdVQ4fJYg== X-Received: by 2002:a5d:45cb:: with SMTP id b11mr1578365wrs.216.1583511534277; Fri, 06 Mar 2020 08:18:54 -0800 (PST) Received: from [10.62.12.18] ([91.206.0.63]) by smtp.gmail.com with ESMTPSA id 2sm13276101wrf.79.2020.03.06.08.18.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Mar 2020 08:18:53 -0800 (PST) Reply-To: f.venchiarutti@ocado.com Subject: Re: Limit transaction lifetime To: Andrei Zhidenkov Cc: pgsql-general@lists.postgresql.org References: <6d6f34b6-c492-2e64-d43a-8be86b0d8a88@ocado.com> From: Fabio Ugo Venchiarutti Organization: Ocado Technology Message-ID: Date: Fri, 6 Mar 2020 16:18:53 +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 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/03/2020 16:14, Andrei Zhidenkov wrote: >=20 >> If it's a single command you're trying to limit `SET statement_timeout T= O ` should do the trick. >=20 > This will set only statement timeout but won=E2=80=99t work for long tran= sactions that contain a lot of short statements. >=20 >> 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 execu= tor hooks (that requires some coding). >=20 > Yes, that=E2=80=99s exactly I want to do. >=20 >> If the queries that worry you are long-lived, you might be able to get b= y 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. >=20 > I think in my case I should check `xact_start`, because not every query i= nitiates a new transaction. That way you'd also be counting in time a given transaction spent=20 idling, which IME is one of the biggest source of concurrency headaches=20 if it's holding locks while doing nothing. If your use case is unaffected by that, that'd be good news for you. --=20 Regards Fabio Ugo Venchiarutti OSPCFC Network Engineering Dpt. Ocado Technology --=20 Notice:=20 This email is confidential and may contain copyright material of=20 members of the Ocado Group. Opinions and views expressed in this message=20 may not necessarily reflect the opinions and views of the members of the=20 Ocado Group. If you are not the intended recipient, please notify us=20 immediately and delete all copies of this message. Please note that it is= =20 your responsibility to scan this message for viruses. References to the=20 "Ocado Group" are to Ocado Group plc (registered in England and Wales with= =20 number 7098618) and its subsidiary undertakings (as that expression is=20 defined in the Companies Act 2006) from time to time. The registered office= =20 of Ocado Group plc is Buildings One & Two, Trident Place, Mosquito Way,=20 Hatfield, Hertfordshire, AL10 9UL.