
Process B is said to have been "blocked" by Process A.

The other process, i.e., Process B waits for Process A to complete so that the lock on the shared piece of data is released. Suppose Process A has locked the piece of shared data. This situation occurs when two processes (say Process A and Process B) need access to the same piece of data at the same point in time.

Relational databases take advantage of locking when running concurrent operations to prevent data inconsistency and data loss. Locking protects data integrity during concurrent transactions. This prevents two SQL statements from updating the row at the same. In order to edit this row, the SQL statement would have to first acquire the lock. Imagine that each row in your table has a "lock". In this section, I'll discuss the concepts to understand why deadlocks occur. Looking for a modern SQL editor? Try Arctype's free SQL editor for easy queries, visualizations, and sharing.

#Postgres deadlock how to#
In this article I'll discuss why deadlocks occur, how different databases handle them, how to resolve them, and tips on how to prevent them. It occurs when two processes attempt to gain exclusive access to a resource, and each of them waits on the other to complete before moving forward. Are you looking to improve your database performance? If you've already taken care of the low-hanging fruit like database indexes, then deadlocks in your database could be the culprit.ĭeadlocks create situations similar to a traffic jam at an intersection, where none of the cars can move.
