Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TM31f-0001eZ-KA for pgsql-hackers@postgresql.org; Wed, 10 Oct 2012 20:37:07 +0000 Received: from mh5.mail.rice.edu ([128.42.199.32]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TM31c-0003p9-Jv for pgsql-hackers@postgresql.org; Wed, 10 Oct 2012 20:37:06 +0000 Received: from mh5.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh5.mail.rice.edu (Postfix) with ESMTP id CFD4611F811; Wed, 10 Oct 2012 15:37:02 -0500 (CDT) Received: from mh5.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh5.mail.rice.edu (Postfix) with ESMTP id AA3F311F858; Wed, 10 Oct 2012 15:37:02 -0500 (CDT) X-Virus-Scanned: by amavis-2.7.0 at mh5.mail.rice.edu, auth channel Received: from mh5.mail.rice.edu ([127.0.0.1]) by mh5.mail.rice.edu (mh5.mail.rice.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id 7_h8wJBQE7UP; Wed, 10 Oct 2012 15:37:02 -0500 (CDT) X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.rice.edu (aart.rice.edu [168.7.56.48]) by mh5.mail.rice.edu (Postfix) with ESMTP id 6EC3411F811; Wed, 10 Oct 2012 15:37:02 -0500 (CDT) Received: by aart.rice.edu (Postfix, from userid 18612) id 56476100F2A; Wed, 10 Oct 2012 15:37:02 -0500 (CDT) Date: Wed, 10 Oct 2012 15:37:02 -0500 From: "ktm@rice.edu" To: Tomas Vondra Cc: pgsql-hackers@postgresql.org Subject: Re: change in LOCK behavior Message-ID: <20121010203702.GA1583@aart.rice.edu> References: <5075D8DF.6050500@fuzzy.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5075D8DF.6050500@fuzzy.cz> User-Agent: Mutt/1.5.20 (2009-12-10) X-Pg-Spam-Score: -6.3 (------) X-Archive-Number: 201210/515 X-Sequence-Number: 214751 On Wed, Oct 10, 2012 at 10:21:51PM +0200, 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). > > regards > Tomas > Hi Tomas, 9.2 is doing it right. Per the documentation on explicit locking: http://www.postgresql.org/docs/9.2/static/explicit-locking.html Tip: Only an ACCESS EXCLUSIVE lock blocks a SELECT (without FOR UPDATE/SHARE) statement. Regards, Ken