Re: can you tell me why this causes a deadlock?





John Rivers wrote:

if you want to do that
you need to ensure you obtain all the locks required for the whole
transaction in the first statement

That is often impossible, eg. a tx that updates two
tables. The actual requirement is that all potentially
concurrent transactions should lock needed objects in
the same order, else deadlocking is a risk.

for example:

Session 1:
BEGIN TRAN
insert into joe with (tablockx) (c1,c2) values (1,2)

Session 2:
BEGIN TRAN
insert into joe with (tablockx) (c1,c2) values (3,4)

Session 1:
select * from joe

Session 2:
select * from joe

deadlocks only occur when developers don't understand locking
and they can render a production system virtually unusable ...

Amen to that, but what I'm looking for is a description of
what two locks my original two transactions got in reverse
order.
thanks
Joe

.



Relevant Pages

  • Re: j2ee architecture advice needed
    ... MySQL tables are not transactional. ... transactions. ... You might want to look at the upcomming EJB 2.1 Web Services, ... > utilize stateless session beans, ...
    (comp.lang.java.programmer)
  • Re: MATREADU/MATWRITE statements timing out
    ... Pessimistic locks for transactions (required for transaction ... Optimistic locks for "masterfile updates" (which 'deteriorate' to ... field by field comparisons during actual update, ...
    (comp.databases.pick)
  • Re: Sql Server Locks
    ... Tran and Commit Tran are as close together as possible and the transactions ... > The problem is with SQL Server Database Locks. ... > client A and reinserts the same with some data changes ... > provide us any good links for this kind of scenarios. ...
    (microsoft.public.sqlserver.clients)
  • Re: Locking question when using Select clause with For Update and Skip locked
    ... This is working fine in SQL Server and multiple session can get the ... But in Oracle the first session only return 1 row but locks all the ...
    (comp.databases.oracle.server)
  • Re: Waiting for smon to disable tx recovery. 9i on unix.
    ... away in a trial and error manner like so many others that I work ... I just waited for the database to shut down. ... Check transactions by user, selecting fields with: ... If a user session attempts ...
    (comp.databases.oracle.server)