Re: Rows with exclusive lock

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Rows with exclusive lock
Date: 2006-07-23 16:10:51
Message-ID: 20060723161050.GC32458@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2006-07-23 18:32:37 Re: Referential integrity (foreign keys) across multiple tables
Previous Message Florian Weimer 2006-07-23 15:28:28 Re: Rows with exclusive lock