Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TM36k-0006IU-5t for pgsql-hackers@postgresql.org; Wed, 10 Oct 2012 20:42:22 +0000 Received: from moutng.kundenserver.de ([212.227.126.171]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TM36i-0001Yx-0Z for pgsql-hackers@postgresql.org; Wed, 10 Oct 2012 20:42:21 +0000 Received: from awork2.localnet (p5DDC7B21.dip.t-dialin.net [93.220.123.33]) by mrelayeu.kundenserver.de (node=mrbap3) with ESMTP (Nemesis) id 0Lzrl5-1TQXGM3cYt-014z9N; Wed, 10 Oct 2012 22:42:18 +0200 From: Andres Freund Organization: 2ndquadrant.com To: pgsql-hackers@postgresql.org Subject: Re: change in LOCK behavior Date: Wed, 10 Oct 2012 22:42:16 +0200 User-Agent: KMail/1.13.7 (Linux/3.6.0-rc7-andres-00118-g66266e1-dirty; KDE/4.8.4; x86_64; ; ) Cc: Tomas Vondra References: <5075D8DF.6050500@fuzzy.cz> In-Reply-To: <5075D8DF.6050500@fuzzy.cz> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit Message-Id: <201210102242.16451.andres@2ndquadrant.com> X-Provags-ID: V02:K0:EMO6b0TjQeBa0Lyt1x1POxcjQql5wbNWT6x9R2jdt2d tCMwc+VNMsqXuG7+MHgAQfdVSgZOSSvGjexaWazax6G4XgBdk2 mqr/8+xpbRCvsLvqovh62Z2OQDFYPio9fWDdMpNSI8+kgUJdU3 fGfv8iCf5nVFPcQ8a9yD1+wK/qOq6aL5o9wBIv08vVfk6dJS9e po1wEViGKN4oMAxeoHHrsdU2OV4T8LsTwrRve2BQmh1lLDTclh gXY3IxWHPNik0c/6dUAJWYvSmASor61seBM6XiZxDPcic7MofF 2vQRKp9eU1RDD4ICEw/02kNeGV8Skvg3Rpt0pA3UAENduRHF02 +esQ3Fhl88YRFrNSyhcAzIU4psoIfQQoG+Y7rD6KsjOrOca+m7 Xht9mR3Z2U8nw== X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201210/517 X-Sequence-Number: 214753 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. Greetings, Andres -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services