Skip site navigation (1) Skip section navigation (2)

Re: update table with row locking

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Mark <sendmailtomark(at)yahoo(dot)com>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: update table with row locking
Date: 2004-12-29 18:19:24
Message-ID: 20041229181924.GA10760@wolff.to (view raw or flat)
Thread:
Lists: pgsql-general
On Wed, Dec 29, 2004 at 07:02:51 -0800,
  Mark <sendmailtomark(at)yahoo(dot)com> wrote:
> In general I need to lock whole  table so only one session can
> perform update. I'm looking for solution that will work in both C++
> and Java.

You probably want to use LOCK. You can read the documention for that command
to help decide which lock you should take.

> 
> Will 'SELECT FOR UPDATE' lock whole table?

No. It will only lock records visible to the current transaction.
In particular this won't keep other transactions from doing inserts
into the table.

> As per 'LOCK' will lock released if connection get closed abnormally?

I believe the locks get released when the backend process terminates.
Depending on how the client dies, there may be a significant delay before
the backend process terminates.

> ( example: hard crash on the client side, network interruptions,
> etc.) Can LOCK be used in JDBC or it's SQL92 standard?

I don't know, but I would be surprised if you couldn't.

In response to

Responses

pgsql-general by date

Next:From: Michael FuhrDate: 2004-12-29 18:20:34
Subject: Re: update table with row locking
Previous:From: Bruno Wolff IIIDate: 2004-12-29 17:38:35
Subject: Re: loading only few rows from huge table

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group