Re: PostgreSQL transaction locking problem - Mailing list pgsql-general

From Mike Mascari
Subject Re: PostgreSQL transaction locking problem
Date
Msg-id 3C5C6E49.480F14F@mascari.com
Whole thread Raw
In response to Re: PostgreSQL transaction locking problem  ("Jeff Martin" <jeff@dgjc.org>)
Responses Running postgresql problem??
List pgsql-general
Jeff Martin wrote:
>
> first the case of my example is just that, an example.  i want to learn to
> use transactions and locking so that i can do the following....
>
> 1. run multiple processes in different transactions,
> 2. executing the same pg/sql functions which,
> 3. need to read data at the beginning of the function that is committed,
> 4. perform calculations and write a result.
> 5. thus competing processes will need to wait for each to commit the result
> in turn.

I kind of missed the beginning of this thread, so pardon me if I'm way
off base. But the behavior you describe just requires the use of
SELECT...FOR UPDATE. The second transaction will block awaiting the
COMMIT/ABORT of the first.

Session #1:

BEGIN;
SELECT balance FROM checking FOR UPDATE;

Session #2:

BEGIN;
SELECT balance FROM checking FOR UPDATE;

 ^== Blocks until Session #1 COMMITS/ABORTS


Hope that helps,

Mike Mascari
mascarm@mascari.com

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: PostgreSQL transaction locking problem
Next
From: David Madore
Date:
Subject: HASH index method not correctly handling NULL text values?