Agent skill · data analytics · jeremylongshore

detecting-database-deadlocks

Process use when you need to work with deadlock detection.

Why this skill is useful

Provides specific SQL commands and strategies for detecting and resolving deadlocks in PostgreSQL and MySQL that the AI wouldn't reliably generate on its own.

What it needs

Requires mysql, psql installed locally. About 4k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.

What this skill does

Database Deadlock Detector Overview 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. Prerequisites Database credentials with access to lock monitoring views (pglocks, INNODBLOCKWAITS) psql or mysql CLI for executing diagnostic queries PostgreSQL: loglockwaits = on and deadlocktimeout = 1s configured MySQL: innodbprintalldeadlocks = ON for deadlock logging to error log Access to database error logs for deadlock event parsing Application source code access for identifying lock-inducing code paths Instructions 1. Check for currently blocked transactions and their blockers: PostgreSQL: SELECT blocked.pid AS blockedpid, blocked.query AS blockedquery, blocking.pid AS blockingpid, blocking.query AS blockingquery FROM pgstatactivity blocked JOIN pglocks bl ON bl.pid = blocked.pid JOIN pglocks bl2 ON bl2.locktype = bl.locktype AND bl2.relation = bl.relation AND bl2.pid != bl.pid JOIN pgstatactivity blocking ON blocking.pid = bl2.pid WHERE NOT bl.granted MySQL: SELECT FROM informationschema.INNODBLOCKWAITS 2. Parse recent deadlock events from database logs: PostgreSQL: Search logs for ERROR: deadlock detected entries, which include the two conflicting queries and the lock types MySQL: Run SHOW ENGINE INNODB STATUS\G and examine the LATEST DETECTED DEADLOCK section Extract: transaction IDs, queries involved, tables and rows locked, and which transaction was rolled back 3. Construct 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. 4. Trace the deadlocking queries back to application code. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills jeremylongshore/detecting-database-deadlocks--0fefb1

View the source on GitHub

Browse the @skills marketplace