Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xo0gL-0006MG-Nt for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2014 01:55:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xo0gL-0002ah-8X for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2014 01:55:45 +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 1Xo0gK-0002ab-Gx for pgsql-bugs@postgresql.org; Tue, 11 Nov 2014 01:55:44 +0000 Received: from nm2.bullet.mail.ne1.yahoo.com ([98.138.90.65]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xo0gH-0002Su-1b for pgsql-bugs@postgresql.org; Tue, 11 Nov 2014 01:55:42 +0000 Received: from [98.138.226.176] by nm2.bullet.mail.ne1.yahoo.com with NNFMP; 11 Nov 2014 01:55:38 -0000 Received: from [98.138.89.165] by tm11.bullet.mail.ne1.yahoo.com with NNFMP; 11 Nov 2014 01:55:38 -0000 Received: from [127.0.0.1] by omp1021.mail.ne1.yahoo.com with NNFMP; 11 Nov 2014 01:55:38 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 731916.69113.bm@omp1021.mail.ne1.yahoo.com Received: (qmail 60306 invoked by uid 60001); 11 Nov 2014 01:55:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1415670938; bh=75NBSaIadnm/6Ycdskb8iDsEmQt4LlP8EYgF77dpnMg=; h=References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=NPWRfUFWrbnHJtGa8bq/CvrjwRBIoJkdoh2N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aGVyZSBjb2RlIHJ1bm5pbmcgd2l0aGluIGEgc2F2ZXBvaW50IGNhbiBzZWUKPiBkYXRhIGNvbW1pdHRlZCBpbiBhIHNlY29uZCBzZXNzaW9uIGFmdGVyIHRoZSBjb21tZW5jZW1lbnQgb2YgdGhlIGZpcnN0LAo.IGJ1dCB0aGEBMAEBAQE- X-Mailer: YahooMailWebService/0.8.203.733 References: <20141108234236.2524.67434@wrigleys.postgresql.org> Message-ID: <1415670938.45502.YahooMailNeo@web122304.mail.ne1.yahoo.com> Date: Mon, 10 Nov 2014 17:55:38 -0800 From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: BUG #11919: Serializable isolation issue: one session seeing writes from another session. To: "gavin.panella@canonical.com" , "pgsql-bugs@postgresql.org" In-Reply-To: <20141108234236.2524.67434@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Pg-Spam-Score: -2.0 (--) 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 "gavin.panella@canonical.com" wrote: > I think I might have found a bug in PostgreSQL 9.3.5 relating to > serializable isolation, where code running within a savepoint can see > data committed in a second session after the commencement of the first, > but that data then "disappears" when the savepoint is rolled-back. > 1. Open two psql sessions to the same database. > > 2. Create an example table: > > create table things (a int unique); > > 3. In the first session: > > begin isolation level serializable; > insert into things (a) values (1); > > Don't commit yet. > > 4. In the second session: > > begin isolation level serializable; > savepoint one; > insert into things (a) values (1); > > This should hang. > > 5. In the first session: > > commit; > > 6. Go back to the second session. It will have failed with: > > ERROR: duplicate key value violates unique constraint "things_a_key" > DETAIL: Key (a)=(1) already exists. > > 7. Continue in the second session: > > rollback to savepoint one; > select * from things; > > You should see: > > a > --- > (0 rows) Interesting. I see your point, yet I'm not sure what other behavior we could reasonably provide. Once the snapshot is set for the transaction, we can't use a different one which will show more recent activity, so that SELECT at the end *has* to return what it does. That leaves the question of whether the enforcement of the unique constraint within the savepoint should behave differently. Of course, you can make it do so by declaring it to be DEFERRED. There are several other weird things that can happen when they aren't deferred, for example: test=# create table things (a int unique); CREATE TABLE test=# insert into things values (1),(2); INSERT 0 2 test=# update things set a = a + 1; ERROR: duplicate key value violates unique constraint "things_a_key" DETAIL: Key (a)=(2) already exists. So I'm not too concerned that this is another thing that doesn't really behave in an ACID manner if the constraint is not declared as DEFERRABLE. If you want truly logical behavior you should always declare constraints that way and just put up with the performance hit that brings. Try playing around with your test case if the table is defined this way: create table things (a int unique deferrable initially deferred); -- 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