Re: How to prevent dead locks ???
Posted in 1998
Venky9970@aol.com wrote:
: We are getting dead lock errors in our production system, I looked at
: informix manual for any hints on preventing it. It was mentioned that
: by using certain algorithms dead lock can be prevented.
: Can anybody let me know how to prevent dead locks.
Here is the postgresql(www.postgresql.org) man page, that I wrote:
FETCH(SQL) PostgreSQL FETCH(SQL)
NAME
lock - exclusive lock a table
SYNOPSIS
lock [table] classname
DESCRIPTION
lock exclusive locks a table inside a transaction. The
classic use for this is the case where you want to select
some data, then update it inside a transaction. If you
don't exclusive lock the table before the select, some
other user may also read the selected data, and try and do
their own update, causing a deadlock while you both wait
for the other to release the select-induced shared lock so
you can get an exclusive lock to do the update.
Another example of deadlock is where one user locks one
table, and another user locks a second table. While both
keep their existing locks, the first user tries to lock
the second user's table, and the second user tries to lock
the first user's table. Both users deadlock waiting for
the tables to become available. The only solution to this
is for both users to lock tables in the same order, so
user's lock aquisitions and requests to not form a dead-
lock.
EXAMPLES
--
-- Proper locking to prevent deadlock
--
begin work;
lock table mytable;
select * from mytable;
update mytable set (x = 100); commit;
SEE ALSO
begin(l), commit(l), select(l).
--
Bruce Momjian | http://www.op.net/~candle
root@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026