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 1pKgGn-0001KZ-8y for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Jan 2023 13:56:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pKgGm-0001AS-2j for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Jan 2023 13:56:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKeuI-0006NW-PH for pgsql-bugs@lists.postgresql.org; Wed, 25 Jan 2023 12:29:38 +0000 Received: from mail.networkname.de ([85.209.200.144]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKeuG-0002mh-4n for pgsql-bugs@lists.postgresql.org; Wed, 25 Jan 2023 12:29:38 +0000 Date: Wed, 25 Jan 2023 13:29:11 +0100 From: Peter Bex To: pgsql-bugs@lists.postgresql.org Subject: Re: Unique constraint error instead of serialization_failure Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, May 21, 2020 at 9:24 AM Benny Kramek wrote: > Hello, I have found an example where I expect to get a serialization failure error, but instead receive a unique constraint error. My understanding is that this is not supposed to happen starting with PostgreSQL version 9.6 because of this patch: > > I'm also running into this bug (with both Postgres 13.7 and 15.1) and am wondering if there's any progress on this bug, or if there is a known workaround for it. After explaining what I saw on IRC, "ysch" (Yaroslav Schekin) pointed me to this wiki page: https://wiki.postgresql.org/wiki/SerializableToDo and I was able to write a test case in my own code base to confirm this is what I'm running into. While fiddling with my tests, I noticed that when you REINDEX _either_ of the indexes in the testcase before starting the transactions, somehow a serialization error is triggered instead of a uniqueness constraint error! I verified that this also happens with the minimal testcase provided by OP. Of course this is not exactly a useful workaround for a production db, but maybe it helps in finding out why this is failing the way it is? Cheers, Peter Bex