In databases, when multiple processes alter the same table or row, each can lock a table or row. When they need to alter or lock the same resource to complete, that can cause deadlocks, or irreconcilable contention between the processes, causing one of them to be stopped by the system.
Questions tagged [database-deadlocks]
612 questions
                    
                    59
                    
            votes
                
                7 answers
            
        What is the difference between "wait-die" and "wound-wait" deadlock prevention algorithms?
What is the difference between wait-die and wound-wait algorithms?
It seems that both of these deadlock prevention techniques are doing the same thing: A Rollback of older process.
What is the difference between the two?
Please provide a suitable…
         
    
    
        Nadeem Bhati
        
- 739
- 1
- 8
- 13
                    42
                    
            votes
                
                6 answers
            
        Implementing retry logic for deadlock exceptions
I've implemented a generic repository and was wondering if there is a smart way to implement a retry logic in case of a deadlock exception?
The approach should be the same for all repository methods. So is there anyway I can avoid writing 'try/catch…
         
    
    
        user1638662
        
- 443
- 1
- 4
- 7
                    40
                    
            votes
                
                2 answers
            
        How is Hibernate deciding order of update/insert/delete
Let's first forget about Hibernate.  Assume that I have two tables, A & B.  Two transactions are updating same records in these two tables, but txn 1 update B and then A, while txn 2 update A then B.  This is a typical deadlock example.  The most…
         
    
    
        Adrian Shum
        
- 38,812
- 10
- 83
- 131
                    39
                    
            votes
                
                2 answers
            
        Deadlocks in PostgreSQL when running UPDATE
I'm a little bit confused reading about PostgreSQL deadlocks.
A typical deadlock example is:
-- Transaction 1
UPDATE customer SET ... WHERE id = 1
UPDATE customer SET ... WHERE id = 2
-- Transaction 2
UPDATE customer SET ... WHERE id = 2
UPDATE…
         
    
    
        vyakhir
        
- 1,714
- 2
- 17
- 21
                    37
                    
            votes
                
                2 answers
            
        Postgres UPDATE with ORDER BY, how to do it?
I need to do a Postgres update on a collection of records & I'm trying to prevent a deadlock which appeared in the stress tests. 
The typical resolution to this is to update records in a certain order, by ID for example - but it seems that Postgres…
         
    
    
        bbozo
        
- 7,075
- 3
- 30
- 56
                    37
                    
            votes
                
                4 answers
            
        What does "lock | communication buffer resources" mean?
I have an error log which reports a deadlock:
Transaction (Process ID 55) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
I am trying to reproduce this…
         
    
    
        Blorgbeard
        
- 101,031
- 48
- 228
- 272
                    35
                    
            votes
                
                4 answers
            
        Working around MySQL error "Deadlock found when trying to get lock; try restarting transaction"
I have a MySQL table with about 5,000,000 rows that are being constantly updated in small ways by parallel Perl processes connecting via DBI.  The table has about 10 columns and several indexes.
One fairly common operation gives rise to the…
         
    
    
        Anon Gordon
        
- 2,469
- 4
- 28
- 34
                    29
                    
            votes
                
                5 answers
            
        What is a deadlock in a database?
What is a deadlock in SQL Server and when it arises? 
What are the issues with deadlock and how to resolve it? 
         
    
    
        VenkatReddy.Ravu
        
- 363
- 1
- 3
- 6
                    27
                    
            votes
                
                2 answers
            
        Retry on deadlock for MySQL / SQLAlchemy
I have searched for quite some time now and can't found a solution to my problem. We are using SQLAlchemy in conjunction with MySQL for our project and we encounter several time the dreaded error: 
1213, 'Deadlock found when trying to get lock; try…
         
    
    
        cp2587
        
- 513
- 1
- 6
- 12
                    24
                    
            votes
                
                1 answer
            
        How to unit test concurrent read/write with PHPUnit?
I recently encountered an issue on a live application.
I realized I had more and more concurrency exceptions and locks with a database.
Basically I start a transaction which requires a SELECT and an INSERT on the same table to commit.
But because…
         
    
    
        Boris Guéry
        
- 47,316
- 8
- 52
- 87
                    21
                    
            votes
                
                1 answer
            
        What does "tuple (0,79)" in postgres log file mean when a deadlock happened?
In postgres log:
2016-12-23 15:28:14 +07 [17281-351 trns: 4280939, vtrns: 3/20] postgres@deadlocks HINT:  See server log for query details.
2016-12-23 15:28:14 +07 [17281-352 trns: 4280939, vtrns: 3/20] postgres@deadlocks CONTEXT:  while locking…
         
    
    
        Hayate
        
- 653
- 1
- 9
- 25
                    21
                    
            votes
                
                1 answer
            
        Avoiding PostgreSQL deadlocks when performing bulk update and delete operations
We have a single table which does not have references to any other tables. 
┬────────────┬─────────────┬───────────────┬───────────────╮
│id_A(bigint)│id_B(bigint) │val_1(varchar) │val_2(varchar)…
         
    
    
        sanjayav
        
- 4,896
- 9
- 32
- 30
                    20
                    
            votes
                
                4 answers
            
        Deadlock error in INSERT statement
We've got a web-based application.  There are time-bound database operations (INSERTs and UPDATEs) in the application which take more time to complete, hence this particular flow has been changed into a Java Thread so it will not wait (block) for…
         
    
    
        Gnanam
        
- 10,613
- 19
- 54
- 72
                    18
                    
            votes
                
                3 answers
            
        SqlException: Deadlock
I have these two exceptions generated when I try to get data from SQL database in C#:
System.Data.SqlClient.SqlException:  Transaction (Process ID 97) was deadlocked on lock resources with another process and has been chosen as the deadlock…
         
    
    
        Harold Sota
        
- 7,490
- 12
- 58
- 84
                    18
                    
            votes
                
                2 answers
            
        How to simulate deadlock in PostgreSQL?
I am new for PostgreSQL. I want to simulate deadlock for this schedule:
How to simulate deadlock in PostgreSQL? Is it possible at all? How to lock particular column?
BEGIN;
UPDATE deadlock_demonstration
SET salary1=(SELECT salary1 
FROM…
         
    
    
        user3388473
        
- 953
- 2
- 12
- 25