pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <kgrittn@ymail.com>
To: Hursh Jain <hurshjain@beesell.com>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: postgres 9.3.6, serialize error with two independent, serially consistent transactions..
Date: Thu, 19 Mar 2015 12:22:35 +0000 (UTC)
Message-ID: <153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <550A2400.8090201@beesell.com>
References: <550A2400.8090201@beesell.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hursh Jain <hurshjain@beesell.com> wrote:

> In the example below, client #1 and client #2 are not doing
> anything that can possibly cause a inconsistent serial order of
> execution. You can pick and choose whichever one you want to run
> first, the final result will be 100% consistent and exactly the
> same, either way.
>
> So why does postgres 9.3.6 give an error to the second client ?
> Unless I am reading this docs wrong, this looks like a major bug.

This is not a bug.  What use of serializable transactions
guarantees is that the behavior of any set of successfully
committed serializable transactions is consistent with some serial
order of execution of those transactions.  If you retry the second
transaction (which got the serialization failure) it will succeed
and you have behavior consistent with either order of execution, so
the conditions are met.  There is no guarantee that there will be
no false positives (where a serialization failure is generated
where with infinite time and resources to analyze everything it
could have been avoided).

Note that if you add a primary key on the id column, and use values
that do not cause duplicate keys, you do not get any error.  Without
an index a full table scan is needed, which causes a predicate lock
which has a rw-conflict with any insert to the table.  Two
transactions doing this concurrently will cause a serialization
failure.  If we tracked enough information to avoid this case,
resource usage and performance would not be in a range most would
consider acceptable; heuristics are needed, which inevitably allows
false positives in some circumstances.

If you try your example on any database which uses strict two phase
locking (S2PL) to implement serializable transactions (e.g., MS SQL
Server, DB2, MySQL, Berkeley DB, etc.), I think you will find that
you also get a false positive serialization failure in the form of
a deadlock.  In databases which do not actually provide
serializable behavior when you ask for it (e.g., Oracle), you will
not get an error.  If you want that level of transaction isolation
in PostgreSQL you can request REPEATABLE READ, and you will
likewise not get an error.  For a description of the differences
between these isolation levels see the docs:

http://www.postgresql.org/docs/current/interactive/mvcc.html

For some examples of cases where you get different results between
these two isolation levels, see:

https://wiki.postgresql.org/wiki/SSI

PostgreSQL gives you a choice of which behavior you prefer.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (3+ messages)  latest in thread

Message-ID: <153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.com>
Permalink:  ../153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.com/
Also on:    postgresql.org/message-id/153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.com

 · 

reply

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: kgrittn@ymail.com, hurshjain@beesell.com
  Subject: Re: postgres 9.3.6, serialize error with two independent, serially consistent transactions..
  In-Reply-To: <153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.com>
  References: <550A2400.8090201@beesell.com> <153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.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