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 B55F69FA43C for ; Sat, 22 Jul 2006 11:56:04 -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 48749-06 for ; Sat, 22 Jul 2006 14:56:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bugs.unl.edu.ar (bugs.unl.edu.ar [168.96.132.208]) by postgresql.org (Postfix) with ESMTP id 696559FA2A9 for ; Sat, 22 Jul 2006 11:56:00 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by bugs.unl.edu.ar (Postfix) with ESMTP id 8DEFF6F90B; Sat, 22 Jul 2006 11:55:39 -0300 (ART) Received: from bugs.unl.edu.ar ([127.0.0.1]) by localhost (bugs.unl.edu.ar [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zu210RZKE0oa; Sat, 22 Jul 2006 11:55:39 -0300 (ART) Received: by bugs.unl.edu.ar (Postfix, from userid 1000) id 9B0646F90A; Sat, 22 Jul 2006 11:55:38 -0300 (ART) Received: from localhost (localhost [127.0.0.1]) by bugs.unl.edu.ar (Postfix) with ESMTP id 78342FF11; Sat, 22 Jul 2006 11:55:38 -0300 (ART) Date: Sat, 22 Jul 2006 11:55:38 -0300 (ART) From: Martin Marques To: Alvaro Herrera cc: pgsql-sql@postgresql.org Subject: Re: Rows with exclusive lock In-Reply-To: <20060722144218.GH5125@surnet.cl> Message-ID: References: <20060722144218.GH5125@surnet.cl> MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: Content-Type: TEXT/PLAIN; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE X-Archive-Number: 200607/288 X-Sequence-Number: 25862 On Sat, 22 Jul 2006, Alvaro Herrera wrote: > Martin Marques escribi=F3: >> 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=20 rows. I want a read/write lock, so no one can access does rows. > >> AFAIK SELECT FOR UPDATE doesn't help with this. > > Why? trans1: prueba2=3D> BEGIN; BEGIN prueba2=3D> SELECT * FROM personas FOR UPDATE; codigo | nombre | apellido | tipodoc | docnum --------+--------+----------+---------+---------- 3 | Martin | Marques | 1 | 23622139 (1 row) Meanwhile, at this moment trans2: prueba2=3D> BEGIN; BEGIN prueba2=3D> SELECT * FROM personas; codigo | nombre | apellido | tipodoc | docnum --------+--------+----------+---------+---------- 3 | Martin | Marques | 1 | 23622139 (1 row) pg_locks shows the the lock is RowShareLock, so there is no read lock on=20 those rows, which is what I want. -- 21:50:04 up 2 days, 9:07, 0 users, load average: 0.92, 0.37, 0.18 --------------------------------------------------------- Lic. Mart=EDn Marqu=E9s | SELECT 'mmarques' || Centro de Telem=E1tica | '@' || 'unl.edu.ar'; Universidad Nacional | DBA, Programador, del Litoral | Administrador ---------------------------------------------------------=