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 1snFwh-002Ape-KC for pgsql-general@arkaria.postgresql.org; Sun, 08 Sep 2024 11:19:08 +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 1snFwg-00CuQm-Py for pgsql-general@arkaria.postgresql.org; Sun, 08 Sep 2024 11:19:06 +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 1snFwg-00CuQd-8K for pgsql-general@lists.postgresql.org; Sun, 08 Sep 2024 11:19:06 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1snFwd-0008GK-2B for pgsql-general@lists.postgresql.org; Sun, 08 Sep 2024 11:19:05 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-374d29ad870so1988510f8f.3 for ; Sun, 08 Sep 2024 04:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1725794343; x=1726399143; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=xlFFzCBbB886V5+bQ8/u0nrGlNw7ILdUkpKRm7kfInQ=; b=VoDbVxkJPw6MZwN7os8pwr04nLXRfF/+TGbyIRLg6yqrCMQu3VS8X+romFTgulO4zK GqQ4fS5+yowEXzpKxqggryqA8Ql0A4Mk4FhNTot0CvkEEo4+mB4Mz0cFwDeUcStfQsCe SUUeaxu9JgEahKo5JxDv6xuegBNDEbaJGU0BYVrsMOQyxjvZJiT6h8K5tLLaVwbqzXmT m9PVNWenBDLpC7li23VgUsQZgBpTxI4I1aG2XZw0wJo5l77VZTBRh/15K8ww1nURKv5Y Zx/u23c6U2PVn0rZ8qQd1aRXgTBPiwwMJJcTKBRIXMEhNfoyjy8KQkPdm0CEahYjSdjo F4ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725794343; x=1726399143; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xlFFzCBbB886V5+bQ8/u0nrGlNw7ILdUkpKRm7kfInQ=; b=LLx0C+0yE5ZUvO0Vd9qo06dq15P/Ln1IWFBrRuMaXXgDHP1G5+jMxk1++IQVbeaYbV ZyanhRIxFsoEwVTrCXLT9nT9zT4Z4W8szPaB43IIEyRUcELbcFW2xHn2pXfkfczlxcyt 3lyP4VqfVpn5KRPggPuIUsdbc8ov+l3mvnbgZ3K6oVaGmZnx3O/9KwUzHASYC6vaqDQE S41iBi3YjrS13VwWHW/cKvpEbaBOg/ij8UmAFPGX6HdOEV6ULtKoLYzYZ3FihFeXv+ux E763IafgNnCWSi7TrbMKUFq0PNDDPShkLvDVVISWWkQ1PuW8Z8ldP8fVxsJAbLZCuU+N 6YIg== X-Forwarded-Encrypted: i=1; AJvYcCWjnVI8O3txhZjVtkhA8TVTKXp30FGmoS4P+cBAjWnYCHGNX4Q96liMxcxoLyWyxeD2JvNmN1wmmUAUb5oO@lists.postgresql.org X-Gm-Message-State: AOJu0YzVUGLAFDvdWvtGibtozHidQPj3BqJoNEdZR3yL5V1eJuQbOFr8 mWiGuNWhkXQApt39tcWbKsjRH3LvZeyBfJQ6TGTzzIO7QkSVO8TnCqki1TIv4c8= X-Google-Smtp-Source: AGHT+IF49uH7Ys1LOqSMMai12KH+36696pD0R4wGVHWZd2svgmvZckTzxEMad8szBT+EcXmGjZYWug== X-Received: by 2002:adf:f70c:0:b0:366:f8e7:d898 with SMTP id ffacd0b85a97d-378896c3b6cmr5359342f8f.50.1725794342330; Sun, 08 Sep 2024 04:19:02 -0700 (PDT) Received: from [10.0.3.10] ([213.235.133.41]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd4696asm1724457a12.30.2024.09.08.04.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Sep 2024 04:19:02 -0700 (PDT) Message-ID: <8fabad5643b3b10355c95e30f4e758c17640d0d0.camel@cybertec.at> Subject: Re: How to cleanup transaction after statement_timeout aborts a query? From: Laurenz Albe To: Istvan Soos , pgsql-general@lists.postgresql.org Date: Sun, 08 Sep 2024 13:18:28 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-1.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2024-09-08 at 12:56 +0200, Istvan Soos wrote: > I'm one of the developers of the Dart-language Postgresql client > package. I am working on adding a feature that may set the > statement_timeout value before a session or a query as the client > requests it, however, I'm stuck with the following error: >=20 > setup: > CREATE TABLE t (id INT PRIMARY KEY); > INSERT INTO t (id) values (1); >=20 > client-1: > BEGIN; > SELECT * FROM t WHERE id=3D1 FOR UPDATE; > >=20 > client-2: > BEGIN; > SET statement_timeout TO 1000; > SELECT * FROM t WHERE id=3D1 FOR UPDATE; > >=20 > After that any query I send through client-2 will get me the following er= ror: >=20 > Severity.error 25P02: current transaction is aborted, commands ignored > until end of transaction block >=20 > Not even ROLLBACK or COMMIT is working. It is the same for both simple > and extended query protocol. Does the client need to send a non-query > message to clean up the transaction state? Or is this connection now > gone for good? ROLLBACK and COMMIT are working: they end the transaction. It is the atomicity guarantee of database transactions: either all statemen= ts succeed, or all fail. I am aware that other databases have a "statement rollback" feature that al= lows the transaction to proceed after an error, but PostgreSQL doesn't. To handle the failure of a statement while allowing the transaction to proc= eed, you can use savepoints. But be warned: don't even think of setting a savep= oint before each statement. That would affect statement performance severely. Yours, Laurenz Albe