From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Claudio Nieder <claudio.nieder.lists@inodes.ch>
To: pgsql-bugs@postgresql.org
Subject: Re: Possible transaction bug with isolation level serialisable?
Date: Thu, 24 Apr 2014 14:52:09 +0300
Message-ID: <5358FAE9.7040805@vmware.com> (raw)
In-Reply-To: <033D7E5E-2F0B-48B6-9E4D-6E7F0CA8B0D9@inodes.ch>
References: <033D7E5E-2F0B-48B6-9E4D-6E7F0CA8B0D9@inodes.ch>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: hlinnakangas@vmware.com, claudio.nieder.lists@inodes.ch
Subject: Re: Possible transaction bug with isolation level serialisable?
In-Reply-To: <5358FAE9.7040805@vmware.com>
References: <033D7E5E-2F0B-48B6-9E4D-6E7F0CA8B0D9@inodes.ch> <5358FAE9.7040805@vmware.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox