Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TM3Co-00029z-M4 for pgsql-hackers@postgresql.org; Wed, 10 Oct 2012 20:48:38 +0000 Received: from [2001:1528:137::f1] (helo=mail.gransy.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TM3Cn-0001e4-0z for pgsql-hackers@postgresql.org; Wed, 10 Oct 2012 20:48:37 +0000 Received: from antispam.gransy.com (antispam.gransy.com [77.78.104.124]) by mail.gransy.com (Postfix) with ESMTP id 5F0CD508A7E for ; Wed, 10 Oct 2012 22:48:36 +0200 (CEST) Received: from mail.gransy.com ([82.208.44.189]) by antispam.gransy.com (antispam.gransy.com [77.78.104.124]) (amavisd-new, port 10024) with ESMTP id AAcDq9g+mdRa for ; Wed, 10 Oct 2012 22:48:36 +0200 (CEST) Received: by mail.gransy.com (Postfix, from userid 5000) id 4DC73508A84; Wed, 10 Oct 2012 22:48:36 +0200 (CEST) Received: from [192.168.1.237] (ip-78-45-133-255.net.upcbroadband.cz [78.45.133.255]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id 156D2508A7E for ; Wed, 10 Oct 2012 22:48:36 +0200 (CEST) Message-ID: <5075DF24.3070906@fuzzy.cz> Date: Wed, 10 Oct 2012 22:48:36 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: pgsql-hackers@postgresql.org Subject: Re: change in LOCK behavior References: <5075D8DF.6050500@fuzzy.cz> <201210102242.16451.andres@2ndquadrant.com> In-Reply-To: <201210102242.16451.andres@2ndquadrant.com> Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:1528:137::f1 (failed) X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201210/519 X-Sequence-Number: 214755 On 10.10.2012 22:42, Andres Freund wrote: > On Wednesday, October 10, 2012 10:21:51 PM Tomas Vondra wrote: >> Hi, >> >> I've just noticed a change of LOCK command behavior between 9.1 and 9.2, >> and I'm not sure whether this is expected or not. >> >> Let's use a very simple table >> >> CREATE TABLE x (id INT); >> >> Say there are two sessions - A and B, where A performs some operations >> on "x" and needs to protect them with an "ACCESS EXCLUSIVE" lock (e.g. >> it might be a pg_bulkload that acquires such locks, and we need to do >> that explicitly on one or two places). >> >> Session B is attempting to read the data, but is blocked and waits. On >> 9.1 it sees the commited data (which is what we need) but on 9.2 it sees >> only data commited at the time of the lock attemt. >> >> Example: >> >> A: BEGIN; >> A: LOCK x IN ACCESS EXCLUSIVE MODE; >> A: INSERT INTO x VALUES (100); >> B: SELECT * FROM x; >> A: COMMIT; >> >> Now on 9.1, B receives the value "100" while on 9.2 it gets no rows. >> >> Is this expected? I suspect the snapshot is read at different time or >> something, but I've checked release notes but I haven't seen anything >> relevant. >> >> Without getting the commited version of data, the locking is somehow >> pointless for us (unless using a different lock, not the table itself). > That sounds like youre using different isolation levels in 9.1 and 9.2. Is that > possible? I.e. your 9.1 test uses read committed, and 9.2 uses repeatable read > or serializable. Nope, it's 'read commited' on both. I haven't touched this, but I've verified it to be sure. ============ 9.1 ============ $ psql testdb psql (9.1.6) Type "help" for help. testdb=# show server_version; server_version ---------------- 9.1.6 (1 row) testdb=# show transaction_isolation ; transaction_isolation ----------------------- read committed (1 row) ============ 9.2 ============ $ psql testdb psql (9.2.0) Type "help" for help. testdb=# show server_version; server_version ---------------- 9.2.0 (1 row) testdb=# show transaction_isolation testdb-# ; transaction_isolation ----------------------- read committed (1 row)