From: Martin Marques <martin@bugs.unl.edu.ar>
To: Alvaro Herrera <alvherre@commandprompt.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Rows with exclusive lock
Date: Sat, 22 Jul 2006 11:55:38 -0300 (ART)
Message-ID: <Pine.LNX.4.64.0607221151080.17932@bugs.unl.edu.ar> (raw)
In-Reply-To: <20060722144218.GH5125@surnet.cl>
References: <Pine.LNX.4.64.0607221135470.17932@bugs.unl.edu.ar>
<20060722144218.GH5125@surnet.cl>
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
---------------------------------------------------------
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: martin@bugs.unl.edu.ar, alvherre@commandprompt.com
Subject: Re: Rows with exclusive lock
In-Reply-To: <Pine.LNX.4.64.0607221151080.17932@bugs.unl.edu.ar>
References: <Pine.LNX.4.64.0607221135470.17932@bugs.unl.edu.ar> <20060722144218.GH5125@surnet.cl> <Pine.LNX.4.64.0607221151080.17932@bugs.unl.edu.ar>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox