Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WdICR-0001ZO-1o for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Apr 2014 11:52:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WdICQ-0000GQ-HG for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Apr 2014 11:52:18 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WdICP-0000Dq-8l for pgsql-bugs@postgresql.org; Thu, 24 Apr 2014 11:52:17 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WdICL-00025J-7H for pgsql-bugs@postgresql.org; Thu, 24 Apr 2014 11:52:15 +0000 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id E7A34282CD; Thu, 24 Apr 2014 04:52:11 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id D829B413A4; Thu, 24 Apr 2014 04:52:11 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 0C761C0053; Thu, 24 Apr 2014 04:52:12 -0700 (PDT) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Thu, 24 Apr 2014 04:52:11 -0700 (PDT) Message-ID: <5358FAE9.7040805@vmware.com> Date: Thu, 24 Apr 2014 14:52:09 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.4.0 MIME-Version: 1.0 To: Claudio Nieder , pgsql-bugs@postgresql.org Subject: Re: Possible transaction bug with isolation level serialisable? References: <033D7E5E-2F0B-48B6-9E4D-6E7F0CA8B0D9@inodes.ch> In-Reply-To: <033D7E5E-2F0B-48B6-9E4D-6E7F0CA8B0D9@inodes.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -7.6 (-------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 04/24/2014 12:54 PM, Claudio Nieder wrote: > Two concurrent transaction first check if a certain value is listed > in a table and if not try to insert it. As the value inserted hasto > be unique and both try to enter the same one, one transaction fails > reporting that the value is already part of the table. As both are > executed within a transaction with isolation level SERIALIZABLE I > would have expected that one of them would return with a > serialization failure, which my program would have been ready to > handle and re-execute the transaction. If I understood correctly, you're getting a "duplicate key value violates unique constraint" error, but you were expecting to get a "serialization failure" error instead, because you're using SERIALIZABLE isolation level. > The reason I think something is fishy is, because I find the > behaviour is somehow similar to a nonrepeatable read which should not > occur with this transaction level. The > > SELECT "userRef" FROM "VerifyQueue" WHERE lower("email")=lower($1) > > reports, that the value is NOT in the table, thus the program then > tries to insert it, and at that point the value is shown as being in > the table. > > So is this a bug, or did I misunderstand something? It's not a bug. Serializable isolation level guarantees that the COMMIT fails (or some earlier statement) with a serialization error, if serializability would otherwise be violated, but it does not guarantee that you won't hit some other constraint first. In this scenario, I think you would indeed get a serialization failure if there was no unique constraint on the table. (I would not recommend removing the constraint, however!) I think you'll just need to teach your application to also retry duplicate key errors. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs