Working around spurious unique constraint errors due to SERIALIZABLE bug

From: Florian Weimer <fweimer(at)bfk(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Working around spurious unique constraint errors due to SERIALIZABLE bug
Date: 2009-07-16 09:28:45
Message-ID: 828wip7z8y.fsf@mid.bfk.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

SERIALIZABLE isolation level doesn't really conform to the spec
because it doesn't deal with phantoms. The only case I've come across
where this actually matters is when you're implementing some sort of
"insert into table if not yet present" operation. This will typically
result in a unique constraint violation.[*]

Usually, constraint violations are programming errors, but not this
one. It's more like a detected deadlock. Is there a way to tell this
type of constraint violation from other types, so that the transaction
can be restarted automatically (as if there was a deadlock)?
Theoretically, PostgreSQL should detect that the conflicting row
wasn't there when the snapshot for the transaction was taken, and
somehow export this piece of information, but I'm not sure if it's
available to the client.

[*] One way to work around this is to batch inserts and eventually
perform them in a background task which doesn't run in parallel, but
this approach isn't always possible.

--
Florian Weimer <fweimer(at)bfk(dot)de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andres Freund 2009-07-16 09:29:15 Re: Using the GEQO
Previous Message Andres Freund 2009-07-16 09:24:59 Re: overwrite the encoding of a database