Re: Waiting on a transaction

From: Matt Miller <mattm(at)epx(dot)com>
To: Bill Moseley <moseley(at)hank(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Waiting on a transaction
Date: 2005-08-16 19:19:04
Message-ID: 1124219944.3714.39.camel@dbamm01-linux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2005-08-16 at 12:01 -0700, Bill Moseley wrote:
> I wondered if my application should set an alarm and timeout
> with an error if, by odd chance, an update hangs.

Here's a way to handle this under the upcoming 8.1 release:

Before you execute the update you can execute SELECT ... FOR UPDATE
NOWAIT to select anything (e.g. dummy constant) from the row that you
want to update. If no error is thrown then you have a lock on your row
and you can confidently proceed with your update. Otherwise someone has
that row locked. At that point you can loop and retry if you want.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-08-16 20:12:27 Re: lock problem
Previous Message Rogério A Bassete 2005-08-16 19:17:43 Error: Unable to look up type id 0