Re: Rows with exclusive lock

From: Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Rows with exclusive lock
Date: 2006-07-22 14:55:38
Message-ID: Pine.LNX.4.64.0607221151080.17932@bugs.unl.edu.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

>
>> AFAIK SELECT FOR UPDATE doesn't help with this.
>
> Why?

trans1:

prueba2=> BEGIN;
BEGIN
prueba2=> SELECT * FROM personas FOR UPDATE;
codigo | nombre | apellido | tipodoc | docnum
--------+--------+----------+---------+----------
3 | Martin | Marques | 1 | 23622139
(1 row)

Meanwhile, at this moment trans2:

prueba2=> BEGIN;
BEGIN
prueba2=> 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
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ín Marqués | SELECT 'mmarques' ||
Centro de Telemática | '@' || 'unl.edu.ar';
Universidad Nacional | DBA, Programador,
del Litoral | Administrador
---------------------------------------------------------

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Florian Weimer 2006-07-23 15:28:28 Re: Rows with exclusive lock
Previous Message Alvaro Herrera 2006-07-22 14:42:18 Re: Rows with exclusive lock