Deadlocks and Lock Contention Troubleshooting
Database lock contention occurs when concurrent transactions need incompatible access to the same resource. A deadlock is a cycle in those waits; troubleshooting identifies the waiting chain, the lock holder, and the transaction design that created it.
itDatabases and data storage | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — Deadlocks and Lock Contention Troubleshooting
Lock contention is what happens when two transactions need access that cannot be granted at the same time. The database is not being difficult for sport. A lock protects a resource while a transaction reads or changes it, so concurrent work does not turn into a collection of accidental interpretations of the same data.
The first useful distinction is wonderfully unsentimental. Blocking means one transaction waits for another, but the holder can still commit or roll back and release the lock. A deadlock is worse in a very specific way: the wait comes back around in a cycle. Transaction A holds what B needs; B holds what A needs. The database ends the stalemate by aborting a victim. Progress resumes, though one request receives the bill.
The map for this small administrative drama is a wait-for graph. Each transaction or session is a node. An arrow points from a waiter to the holder. Follow arrows to a head blocker and you have a chain. Follow them until they return to an earlier node and you have a deadlock. The slow request that prompted the investigation is often merely the messenger, which is an unfair job but a common one.
The surprising part is that current SQL can be poor evidence. A transaction may acquire a lock, run another statement, and then sit idle while still holding it. That is why transaction start time, earlier statements, session state, application identity, and the resource itself belong in the incident record. Live lock views are snapshots. Logs, event capture, sampling, and application telemetry remember the bit that disappeared while someone found the dashboard.
Durable fixes live in the shape of the work. Acquire shared resources in a consistent order. Keep transactions no longer than the business invariant needs. Move network calls and unrelated computation outside them. Use selective access paths so a statement does not touch more rows than intended. Retries matter too, but only for the entire failed transaction, only after cleanup, and only when repeating external effects is safe. A retry loop is a recovery mechanism, not a forgiving substitute for a design.
For the fuller map, use the Intro for the concurrency path and engine-specific interpretation. Open Slides for the graph shapes and investigation order. Keep the Cheatsheet nearby during an incident for the evidence bundle and PostgreSQL, MySQL InnoDB, and SQL Server observation surfaces. The Quiz is where the terminology stops pretending it can hide behind a diagram.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://www.postgresql.org/docs/current/explicit-locking.html
Supports
- PostgreSQL lock modes, row and advisory locking
- Deadlock cycle example and consistent acquisition order
- Intro, slides, cheatsheet, quiz, and reference rationale
- https://www.postgresql.org/docs/current/monitoring-locks.html
Supports
- pg_locks as the view of outstanding locks
- Contention investigation and reference rationale
- https://www.postgresql.org/docs/current/view-pg-locks.html
Supports
- Granted and waiting lock request interpretation
- PostgreSQL observation map
- https://www.postgresql.org/docs/current/monitoring-stats.html
Supports
- pg_stat_activity state and wait-event interpretation
- Active but blocked sessions
- Current-state evidence limits
- https://www.postgresql.org/docs/current/functions-info.html
Supports
- pg_blocking_pids blocker lookup
- PostgreSQL quiz and observation guidance
- https://www.postgresql.org/docs/current/runtime-config-locks.html
Supports
- deadlock_timeout behavior and diagnostic tradeoff
- log_lock_waits timing relationship
- https://dev.mysql.com/doc/refman/8.0/en/innodb-locking.html
Supports
- InnoDB lock types and engine-specific resource interpretation
- Reference-path rationale
- https://dev.mysql.com/doc/refman/8.0/en/innodb-deadlocks.html
Supports
- InnoDB deadlock concepts and documentation path
- Reference-path rationale
- https://dev.mysql.com/doc/refman/8.0/en/innodb-deadlock-detection.html
Supports
- Automatic detection, victim rollback, and detector cost
- Timeout behavior when detection is disabled
- https://dev.mysql.com/doc/refman/8.0/en/innodb-deadlocks-handling.html
Supports
- Application retry expectation
- Short transactions and consistent operational handling
- Quiz explanations
- https://dev.mysql.com/doc/refman/8.0/en/performance-schema-data-locks-table.html
Supports
- Held and requested InnoDB lock data
- Cross-engine observation map
- https://dev.mysql.com/doc/refman/8.0/en/performance-schema-data-lock-waits-table.html
Supports
- Requesting-to-blocking lock relationships
- MySQL observation, quiz, and reference rationale
- https://dev.mysql.com/doc/refman/8.0/en/innodb-information-schema-transactions.html
Supports
- INNODB_TRX transaction state and lock-wait context
- https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-deadlocks-guide
Supports
- Blocking versus deadlocking
- Victim selection and transaction rollback
- xml_deadlock_report, system_health, and graph structure
- Intro, slides, cheatsheet, quiz, and reference rationale
- https://learn.microsoft.com/en-us/troubleshoot/sql/database-engine/performance/understand-resolve-blocking
Supports
- Head-blocker investigation and DMV collection
- Earlier statements in a transaction
- Extended Events evidence and transaction redesign
- https://github.com/sindresorhus/awesome
Supports
- Required discovery route to Database Tools and PostgreSQL awesome lists
- https://github.com/dhamaniasad/awesome-postgres
Supports
- Discovery of pg_activity, pgmetrics, pganalyze, and Percona Monitoring and Management
- https://github.com/mgramin/awesome-db-tools
Supports
- Cross-check of monitoring and performance tools relevant to database troubleshooting
- https://pgmetrics.io/docs/
Supports
- Granted and waiting locks, blocked queries, deadlocks, and structured snapshots
- Awesome Links rationale
- https://github.com/dalibo/pg_activity
Supports
- Live PostgreSQL activity, wait-event, and blocking-query panels
- Awesome Links rationale
- https://pganalyze.com/docs/connections
Supports
- Historical PostgreSQL wait events, blocking chains, and root-blocker display
- Awesome Links rationale and Landscape placement
- https://docs.percona.com/percona-monitoring-and-management/3/
Supports
- Open-source cross-database observability scope
- Awesome Links rationale and Landscape placement
- https://docs.percona.com/percona-monitoring-and-management/3/reference/dashboards/dashboard-postgresql-instances-overview-extended.html
Supports
- Lock counts, deadlock rates, long transactions, and query activity
- Awesome Links rationale and Landscape placement
- https://docs.datadoghq.com/database_monitoring/
Supports
- Cross-engine query samples, historical metrics, blocking queries, and calling-service context
- Landscape placement
- https://docs.datadoghq.com/monitors/types/database_monitoring/
Supports
- Waiting-query monitors and threshold alerts
- Landscape placement
- https://documentation.red-gate.com/monitor14/blocking-processes-overview-239668409.html
Supports
- SQL Server historical and current blocking trees
- Landscape placement
- https://www.red-gate.com/products/redgate-monitor/resources/getting-started-with-sql-monitor-deadlocks/
Supports
- SQL Server deadlock monitoring workflow
- Landscape placement
- https://documentation.solarwinds.com/en/success_center/observability/content/intro/database/deadlocks.htm
Supports
- Captured SQL Server deadlock events, lock ownership, and wait relationships
- Landscape placement
- https://www.dynatrace.com/platform/database-monitoring/
Supports
- Cross-engine locks, deadlocks, and blocking-session investigation
- Landscape placement
- https://www.postgresql.org/files/documentation/pdf/7.1/admin.pdf
Supports
- Timeline research found mature deadlock-timeout behavior in early PostgreSQL documentation
- Evidence that vendor histories do not form one coherent vendor-neutral troubleshooting timeline
- https://dev.mysql.com/doc/refman/8.0/en/performance-schema-data-locks-table.html
Supports
- Timeline research found the MySQL 8 transition from INNODB_LOCKS to Performance Schema data_locks
- Timeline false decision because isolated vendor milestones do not meet the topic-wide arc gate
- https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-deadlocks-guide
Supports
- Timeline research found SQL Server 2012 Extended Events guidance
- Timeline false decision because vendor-specific milestones cannot be combined into one technology history
- https://incident.io/blog/database-performance
Supports
- Field Notes: connection-pool waits, per-operation occupancy, and the cost of many short transactions
- https://useautumn.com/blog/post-mortem-database-outage-caused-by-collation-migration-locking-conflict
Supports
- Field Notes: exclusive-lock risk of in-place schema changes and the duplicate-dual-write-cutover alternative
- https://clerk.com/blog/2026-03-10-service-outage-postmortem
Supports
- Field Notes: lock contention can saturate application compute while database CPU remains normal; replica routing did not mitigate a primary-side incident
