Re: PostgreSQL transaction locking problem

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: jeff(at)dgjc(dot)org
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PostgreSQL transaction locking problem
Date: 2002-02-02 22:55:05
Message-ID: 3C5C6E49.480F14F@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)mascari(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Madore 2002-02-02 23:49:15 HASH index method not correctly handling NULL text values?
Previous Message Tom Lane 2002-02-02 22:35:42 Re: PostgreSQL transaction locking problem