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
Intro
Database lock contention is competition between concurrent transactions for access that cannot be granted at the same time. A lock protects a database resource while a transaction reads or changes it. When a requested lock conflicts with a lock already held, the requester waits. That wait is blocking. A deadlock is a closed cycle: every transaction in the cycle waits for a resource held by another transaction in the same cycle.
Blocking and deadlocking require different responses. Ordinary blocking has a path forward because a holder can commit or roll back and release its locks. A deadlock has no path forward without intervention. A database engine detects the cycle, chooses a victim, rolls that transaction back, and lets the others continue. The application receives an error for the victim transaction. That error is a recovery mechanism, not proof that the underlying access pattern is safe.
The concurrency path
A troubleshooting investigation follows the path of one request:
- A session begins a transaction and executes a statement.
- The engine requests locks for the rows, index entries, pages, tables, metadata, or other resources the statement touches.
- The lock manager compares each request with locks already granted.
- A compatible request proceeds. An incompatible request enters a wait queue.
- The session remains blocked until the holder releases the resource, a timeout or cancellation ends the wait, or deadlock detection finds a cycle.
- If a deadlock exists, the engine aborts a victim transaction. The application must roll back any remaining transaction state and decide whether replay is safe.
Multi-version concurrency control reduces many read-versus-write conflicts by letting readers use a snapshot. It does not remove locks. Writers can still conflict with writers. Locking reads, schema changes, foreign-key checks, uniqueness enforcement, and explicit locks can still wait. The exact resources and compatibility rules vary by engine, so evidence must come from the affected engine rather than from a generic lock chart alone.
Wait-for graphs and blocking chains
Continue the course
This section is part of the paid course.
See pricing to subscribe, or log in if you already have access.
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
