From: | <drevil(at)sidereal(dot)kz> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | How to use locks, for DB noivces? |
Date: | 2001-03-09 21:12:55 |
Message-ID: | 20010309211255.24162.qmail@mailhost.sidereal.kz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I've never used the locking features of Postgres before, and now I
find that I need to use them. I read through the instructions, but
I've never taken a database theory course so I don't understand all
the terms they used.
Here's what I need to do: The database keeps accounts. If one process
is accessing an account, no other process should be able to access it
at the same time. I need to do the following logical sequence of
things:
1. Lock the account
2. Check to see if the change to the account is permitted
3. Make the change
4. Unlock the account
I need this so that there isn't a race condition. Ie, if there are
$10 in the account, and one backen says "withdraw $9" and the other
also says "withdraw $9" at the same time, I need to make sure they
they don't execute at the same time, which would result in a negative
balance.
I tried to do this with SELECT FOR UPDATE but I couldn't get that to
work.
Thanks
From | Date | Subject | |
---|---|---|---|
Next Message | Mike Mascari | 2001-03-09 21:27:26 | RE: How to use locks, for DB noivces? |
Previous Message | Ben | 2001-03-09 20:41:03 | Re: what's going on here? |