Re: update table with row locking - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: update table with row locking
Date
Msg-id 20041229181924.GA10760@wolff.to
Whole thread Raw
In response to Re: update table with row locking  (Mark <sendmailtomark@yahoo.com>)
Responses Re: update table with row locking
List pgsql-general
On Wed, Dec 29, 2004 at 07:02:51 -0800,
  Mark <sendmailtomark@yahoo.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.

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: loading only few rows from huge table
Next
From: Michael Fuhr
Date:
Subject: Re: update table with row locking