Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YYgOD-0006wz-Sx for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Mar 2015 19:45:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YYgOD-0004g3-5G for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Mar 2015 19:45:57 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YYgOC-0004dt-6b for pgsql-bugs@postgresql.org; Thu, 19 Mar 2015 19:45:56 +0000 Received: from smtp122.iad3a.emailsrvr.com ([173.203.187.122]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YYgO8-0003xD-9y for pgsql-bugs@postgresql.org; Thu, 19 Mar 2015 19:45:54 +0000 Received: from smtp16.relay.iad3a.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp16.relay.iad3a.emailsrvr.com (SMTP Server) with ESMTP id 17A80180365; Thu, 19 Mar 2015 15:45:51 -0400 (EDT) Received: by smtp16.relay.iad3a.emailsrvr.com (Authenticated sender: hurshjain-AT-beesell.com) with ESMTPSA id A7AFF180228; Thu, 19 Mar 2015 15:45:50 -0400 (EDT) X-Sender-Id: hurshjain@beesell.com Received: from [192.168.1.7] (pool-98-114-164-232.phlapa.east.verizon.net [98.114.164.232]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA) by 0.0.0.0:465 (trex/5.4.2); Thu, 19 Mar 2015 19:45:51 GMT Message-ID: <550B276C.7080807@beesell.com> Date: Thu, 19 Mar 2015 15:45:48 -0400 From: Hursh Jain User-Agent: Postbox 3.0.11 (Macintosh/20140602) MIME-Version: 1.0 To: Kevin Grittner CC: "pgsql-bugs@postgresql.org" Subject: Re: postgres 9.3.6, serialize error with two independent, serially consistent transactions.. References: <550A2400.8090201@beesell.com> <153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <153754345.412294.1426767755926.JavaMail.yahoo@mail.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) 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 Thanks for this clarification. If you look at the documentation here: http://www.postgresql.org/docs/9.4/static/transaction-iso.html The Serialization example (with the sum being 330/300 based on execution order) implies that the opposite would work, when there were serially consistent updates. However, the second transaction could still fail (unless retried). > 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). It would be very helpful to have the above paragraph (and in fact the larger exposition you typed below) in the documentation itself! The current example on that page implies that serialization *only* fails because of order related inconsistencies, however, it can also fail because of false positives and this should really be mentioned as well. Currently, this is only vaguely alluded to, via 1 sentence (the last line) on that page: "A sequential scan will always necessitate a relation-level predicate lock" which doesn't really mean too much to a lot of people who are getting started.. Best, --Hursh Kevin Grittner wrote: > Hursh Jain 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