Re: Rows with exclusive lock - Mailing list pgsql-sql

From Alvaro Herrera
Subject Re: Rows with exclusive lock
Date
Msg-id 20060723161050.GC32458@surnet.cl
Whole thread Raw
In response to Re: Rows with exclusive lock  (Martin Marques <martin@bugs.unl.edu.ar>)
Responses Re: Rows with exclusive lock  (Martin Marques <martin@bugs.unl.edu.ar>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Florian Weimer
Date:
Subject: Re: Rows with exclusive lock
Next
From: Bruno Wolff III
Date:
Subject: Re: Referential integrity (foreign keys) across multiple tables