Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVJnq-00055j-5K for pgsql-sql@arkaria.postgresql.org; Thu, 23 Feb 2023 22:11:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pVJno-0002i8-Pw for pgsql-sql@arkaria.postgresql.org; Thu, 23 Feb 2023 22:11:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVJno-0002hy-DO for pgsql-sql@lists.postgresql.org; Thu, 23 Feb 2023 22:11:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVJnl-0002gv-R4 for pgsql-sql@lists.postgresql.org; Thu, 23 Feb 2023 22:10:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 31NMAuHT719367; Thu, 23 Feb 2023 17:10:56 -0500 From: Tom Lane To: michele curioni cc: pgsql-sql@lists.postgresql.org Subject: Re: Could not serialize access due to read/write dependencies among transactions In-reply-to: References: Comments: In-reply-to michele curioni message dated "Thu, 23 Feb 2023 21:18:20 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <719365.1677190256.1@sss.pgh.pa.us> Date: Thu, 23 Feb 2023 17:10:56 -0500 Message-ID: <719366.1677190256@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk michele curioni writes: > we have a Spring Boot application that tries to update two separate rows in > a table in 2 separate threads, and it uses the default Transaction > Isolation level of READ_COMMITTED. > One of the two threads always succeeds, the other always fails with: > org.postgresql.util.PSQLException: ERROR: could not serialize access > due to read/write dependencies among transactions > [java] ERROR> Detail: Reason code: Canceled on identification as a > pivot, during write. > [java] ERROR> Hint: The transaction might succeed if retried. > I thought that error could only happen for SERIALIZABLE transactions, Indeed. I think you're mistaken to claim that the transactions are running in READ COMMITTED. > moreover, the two threads are trying to update different rows. That part's not so hard to explain: serializable mode's tracking of which rows received updates is a bit lossy. It might be complaining just because the updated rows were on the same page. regards, tom lane