I use PostgreSQL 9.2, and I do not use explicit locking anywhere, neither LOCK
statement nor SELECT ... FOR UPDATE
. However, recently I got ERROR: 40P01: deadlock detected
. The query where deadlock was detected is wrapped in transaction block though. Anyway, how comes it?
Tell me more
×
Database Administrators Stack Exchange is a question and answer site for
database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.
|
|||
|
Suppose session 1 does:
and at the exact same time session 2 does the opposite:
Then session 1 will be waiting for session 2 to commit or rollback the update on the row where pk = 2 while at the same time session 2 will be waiting for session 1 to commit or rollback the update on the row where pk = 1. Deadlock. |
|||||||||||
|