Re: Apparent bug in transaction processing in serializable mode - Mailing list pgsql-jdbc

From Tom Lane
Subject Re: Apparent bug in transaction processing in serializable mode
Date
Msg-id 25792.1040577146@sss.pgh.pa.us
Whole thread Raw
In response to Apparent bug in transaction processing in serializable mode  (Jan Hlavatý <Jan.Hlavaty@code.cz>)
List pgsql-jdbc
=?ISO-8859-2?Q?Jan_Hlavat=FD?= <Jan.Hlavaty@code.cz> writes:
> On one connection, I perform select on record with for update clause.
> This is supposed to lock the record with update type lock against other
> concurrent updates.
> Then I update that record with new number. All this should do is upgrade
> update lock to exclusive one.

You seem to be operating from a number of incorrect assumptions about
how Postgres' concurrency model works.  For starters, there's only one
kind of row lock, not two kinds.  But more fundamentally, you are trying
to use serializable mode in a way that's really only appropriate for
read-committed mode.  The idea of serializable mode is that a
transaction fails (and should be retried from the top) if it finds
itself wanting to update any concurrently-updated row.  To do otherwise
would violate the very notion of serializability, namely that you don't
see any concurrently-made database changes.  For effective use of
serializable mode, you must adopt an optimistic locking philosophy: you
don't bother with "select for update", you just try to make your updates
and see if they succeed or not.

You might find it useful to look through the slides from my talk on
"PostgreSQL Concurrency Issues" last summer at OSCON 2002 --- see
http://conferences.oreillynet.com/cs/os2002/view/e_sess/2681

            regards, tom lane

pgsql-jdbc by date:

Previous
From: Tom Lane
Date:
Subject: Re: Patch against 7.3.1 AbstractJdbc1Connection.java to allow schema in connectionURL
Next
From: "Peter Adamek Jr."
Date:
Subject: Stored procedures/functions that can return recordsets...