X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 5BDC09FA65C for ; Sun, 23 Jul 2006 13:11:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 26951-04 for ; Sun, 23 Jul 2006 16:11:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx3.surnet.cl (mx3.surnet.cl [216.155.73.182]) by postgresql.org (Postfix) with ESMTP id ADC769FA47F for ; Sun, 23 Jul 2006 13:11:01 -0300 (ADT) Received: from 201-221-221-58.bk12-dsl.surnet.cl (HELO alvh.no-ip.org) ([201.221.221.58]) by mx3.surnet.cl with ESMTP; 23 Jul 2006 12:10:58 -0400 X-IronPort-AV: i="4.07,173,1151899200"; d="scan'208"; a="26767194:sNHT19773520" Received: by alvh.no-ip.org (Postfix, from userid 1000) id 26587C5CDC3; Sun, 23 Jul 2006 12:10:51 -0400 (CLT) Date: Sun, 23 Jul 2006 12:10:51 -0400 From: Alvaro Herrera To: Martin Marques Cc: pgsql-sql@postgresql.org Subject: Re: Rows with exclusive lock Message-ID: <20060723161050.GC32458@surnet.cl> Mail-Followup-To: Martin Marques , pgsql-sql@postgresql.org References: <20060722144218.GH5125@surnet.cl> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.11+cvs20060403 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.043 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, FORGED_RCVD_HELO X-Spam-Level: ** X-Archive-Number: 200607/290 X-Sequence-Number: 25864 Martin Marques escribió: > On Sat, 22 Jul 2006, Alvaro Herrera wrote: > > >Martin Marques escribió: > >>Is it posible to get an exclusive (read/write) lock on certain rows? I > >>don't want to block the whole table, only certain rows, but I want it to > >>be a read/write lock. > > > >That's what SELECT FOR UPDATE does. > > Hi Alvaro, > > After the SELECT FOR UPDATE other transactions can still see the locked > rows. I want a read/write lock, so no one can access does rows. SELECT FOR UPDATE acquires an exclusive lock, but other transactions must try to acquire a lock on the rows as well, or they won't be locked. You can try using SELECT FOR SHARE (new as of 8.1) if you want some transactions to hold shared (read) locks. IOW, SELECT FOR UPDATE blocks other SELECTs FOR UPDATE and SELECTs FOR SHARE, but it does not block plain SELECT. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support