Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uzqMI-007iVV-SZ for pgsql-novice@arkaria.postgresql.org; Sat, 20 Sep 2025 05:42:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uzqMF-00Abxs-Cx for pgsql-novice@arkaria.postgresql.org; Sat, 20 Sep 2025 05:42:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uzqMF-00Abxh-4U for pgsql-novice@lists.postgresql.org; Sat, 20 Sep 2025 05:42:03 +0000 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uzqMA-001ouE-3B for pgsql-novice@postgresql.org; Sat, 20 Sep 2025 05:42:02 +0000 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:6694:0:640:e931:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id CD80DC0234; Sat, 20 Sep 2025 08:41:57 +0300 (MSK) Received: from [10.215.138.152] (unknown [2a02:6bf:8080:b43::1:17]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id DfMV4C1GueA0-cgllrIdK; Sat, 20 Sep 2025 08:41:57 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1758346917; bh=64/v3tFLT8+A9dqOXviKWfN9gKGzrll0J6MyOBbbsZw=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=rePEMBWAc3NQbiTBIRPK6S1RAfiP+QMMHxecJ7hXpBlMLhDuenNiLKbARCG25+42d L549COVvqz4GhQ+zG1EiYMoTIQViGHDTLB4j/xdnkNklKvAcZnRu/fhlOh4fX7YhKo Or8wJ1bUzWtoMhc73LWERrPnFurvAlN5VI+4KL64= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: x4mmm@yandex-team.ru To: Quentin de Metz Cc: pgsql-novice@postgresql.org, amborodin@acm.org, aekorotkov@gmail.com, japinli@hotmail.com, zhjwpku@gmail.com Subject: Re: SET transaction_timeout inside a transaction Date: Sat, 20 Sep 2025 10:41:01 +0500 X-Mailer: MailMate Trial (2.0r6272) Message-ID: <34EA56AD-712D-4DEF-91B9-74FA1673A95D@yandex-team.ru> In-Reply-To: <554670a7-7560-4d18-8ecb-8518fddf2b9d@app.fastmail.com> References: <554670a7-7560-4d18-8ecb-8518fddf2b9d@app.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; markup=markdown Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 20 Sep 2025, at 1:12, Quentin de Metz wrote: > It appears that changing the transaction_timeout when inside a transact= ion does not work as expected. > > Running the following script on master: > > SET transaction_timeout =3D '1s'; > BEGIN; > SET transaction_timeout =3D '3s'; > SELECT pg_sleep(2); > > Fails with the following: > > FATAL: terminating connection due to transaction timeout > server closed the connection unexpectedly > This probably means the server terminated abnormally > before or while processing the request. > > A workaround is to "SET transaction_timeout =3D 0" before each override= =2E But this resets the timer, which may not be aligned with this paramet= er's intention. > Hi Quentin! Thanks for raising this, it's very good to hear more about usage patterns= , it really helps to improve. Together with reviewers we did consider "extending" transaction timeout. = But the problem is it promotes very unreliable coding pattern: adjusting = time budget without checking how many time is already spent. Yes, if expectations of your transaction changed you can reset transactio= n_timeout and set new time budget. Personally, I don't like it either. Bu= t it did not seem a good idea to forbid resetting timeout at all or to fo= rbid setting it amid of a transaction: we needed both this functionalitie= s for "SET transaction_timeout =3D x;" to work. It's hard to change anything radically in shipped feature. But, if possib= le, please, tell more about usage patterns beyond pg_sleep(), maybe our a= ssumptions were not accurate enough and we could do better in future. Best regards, Andrey Borodin.