Re: a SELECT FOR UPDATE question

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Tim Vadnais <tvadnais(at)bwks(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: a SELECT FOR UPDATE question
Date: 2005-02-08 01:09:41
Message-ID: 20050208010941.GA43902@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Feb 07, 2005 at 03:08:12PM -0800, Tim Vadnais wrote:
>
> If I select a row for update, is there anyway that someone can query to see
> if that row has been 'selected for update' and by whom?

I think you can infer that a process is working with a row in some
manner (UPDATE, SELECT FOR UPDATE) by looking at the row's xmax
column and checking pg_locks to see if any process is holding a
lock on the indicated transaction ID. But why do you need to know?
What are you trying to do?

> Then I'd like to know if the session that 'SELECT(ed) FOR UPDATE' dies, will
> the server release the locked row?

Locks should be released when the holding transaction terminates.
I'm not sure if it's possible for a connection to end and leave a
lock behind, but if it is, I suspect it would be considered a bug
in the server that needed to be fixed.

(This sounds familiar, like I've participated in a thread on this
topic before. I get the feeling Tom Lane is going to step in and
provide The Real Answer, and that my radio is about to start playing
"I Got You, Babe"....)

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message CoL 2005-02-08 02:10:17 Re: Sorting when "*" is the initial character
Previous Message Steve Atkins 2005-02-08 00:25:10 Re: Creating an index-type for LIKE '%value%'