Install any skill in seconds. Free to start, no credit card required.
Get Started Free →jeremylongshore/detecting-database-deadlocks
Process use when you need to work with deadlock detection. This skill provides deadlock detection and resolution with comprehensive guidance and automation. Trigger with phrases like "detect deadlocks", "resolve deadlocks", or "prevent deadlocks".
Passed 15 of 19 test cases with the skill, and 14 of 19 without it.
1 fixed16 passed either way5 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
A test case the skill fixed. Same model, same prompt, with and without the skill.
We need an SQL query to inspect active InnoDB lock waits directly in MySQL's metadata views. Which table should we query to inspect current lock wait relationships?
| Checked | Without skill | With skill |
|---|---|---|
| Queries information_schema.INNODB_LOCK_WAITS to inspect active lock waits | Missed | Passed |
The instructions your model reads when the skill loads.
Detect, analyze, and prevent database deadlocks in PostgreSQL, MySQL, and MongoDB by examining lock wait graphs, parsing deadlock log entries, identifying the application code paths that cause lock ordering conflicts, and implementing preventive patterns.
pg_locks, INNODB_LOCK_WAITS)psql or mysql CLI for executing diagnostic querieslog_lock_waits = on and deadlock_timeout = 1s configuredinnodb_print_all_deadlocks = ON for deadlock logging to error logCheck for currently blocked transactions and their blockers:
SELECT blocked.pid AS blocked_pid, blocked.query AS blocked_query, blocking.pid AS blocking_pid, blocking.query AS blocking_query FROM pg_stat_activity blocked JOIN pg_locks bl ON bl.pid = blocked.pid JOIN pg_locks bl2 ON bl2.locktype = bl.locktype AND bl2.relation = bl.relation AND bl2.pid != bl.pid JOIN pg_stat_activity blocking ON blocking.pid = bl2.pid WHERE NOT bl.grantedSELECT * FROM information_schema.INNODB_LOCK_WAITSParse recent deadlock events from database logs:
ERROR: deadlock detected entries, which include the two conflicting queries and the lock typesSHOW ENGINE INNODB STATUS\G and examine the LATEST DETECTED DEADLOCK sectionConstruct the lock wait graph from the deadlock log. Map which transaction held which lock and which lock each transaction was waiting for. The circular dependency reveals the deadlock cycle. Identify the specific rows or index ranges involved.
Trace the deadlocking queries back to application code. Use Grep to find the SQL statements in the codebase and identify the transaction boundaries (BEGIN/COMMIT blocks or ORM transaction decorators). Map the full sequence of operations within each transaction.
Identify the root cause pattern:
READ COMMITTED isolation.Implement deadlock prevention strategies:
SELECT ... FOR UPDATE NOWAIT or SKIP LOCKED to fail fast instead of waitingtest cases passed, vs 14 / 19 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.