# Database Deadlock Analyzer for MySQL and PostgreSQL

> Give it a MySQL or PostgreSQL deadlock log and get the rows involved, the pattern behind the deadlock and the code change that stops it.

Database Deadlock Analyzer for MySQL and PostgreSQL is a paid AI agent skill on Agensi by Singgih Rochmad Saputro, in DevOps & Cloud. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $1 (one-time purchase)
- Creator: [Singgih Rochmad Saputro](https://www.agensi.io/creators/singgihrs)
- Category: [DevOps & Cloud](https://www.agensi.io/skills/devops-cloud)
- Version: 1.0
- Last updated: 2026-12-04
- Security: scan passed (2026-12-04); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/database-deadlock-analyzer-for-mysql-and-postgresql
- Tags: coding, devops, data

## What it does

- Turns a cryptic deadlock log into a table of what each transaction ran, held and waited for
- Shows the actual rows and keys involved instead of hex dumps
- Groups repeated deadlocks so you fix the pattern that happens most
- Names the cause in plain words, such as rows updated in opposite order or check-then-insert
- Gives the code change for each cause, with examples to copy
- Reminds you to retry the rolled-back transaction and shows how

## Who it's for

- **Backend developers seeing deadlock errors in production:** Find which code paths collide and how to change them, from the log you already have. Try: "We get 'Deadlock found when trying to get lock' every day. Here is SHOW ENGINE INNODB STATUS."
- **DBAs and SREs on call for database incidents:** Group a day of deadlocks from the error log and hand developers the pattern and the fix. Try: "Summarize the deadlocks in this MySQL error log and tell me which one to fix first."
- **Teams running database migrations:** See why a migration deadlocked with live traffic and how to run it safely. Try: "Our ALTER TABLE deadlocked in production. Here is the PostgreSQL log."

## About this skill

A deadlock log says which transactions collided but not why. MySQL's InnoDB output is hex dumps of index records and lock modes like "lock_mode X locks gap before rec insert intention waiting"; PostgreSQL's is two process ids and a transaction number. This skill reads them, decodes the rows and keys involved, groups repeated deadlocks, and names the pattern behind each, because every pattern has a different fix.

**Reads**
- The LATEST DETECTED DEADLOCK section of SHOW ENGINE INNODB STATUS (MySQL 5.7 and 8).
- MySQL error logs written with innodb_print_all_deadlocks, with every deadlock.
- PostgreSQL logs with "deadlock detected", and application exceptions that quote them.

**Recognizes**
- Rows updated in opposite order (including the same code path called with items in different order).
- Check-then-insert races on gap locks, and concurrent inserts of the same unique key.
- Foreign key checks: a child insert locking the parent row, then the parent being updated.
- A secondary index and the primary key locked in opposite order.
- AUTO-INC table locks, and PostgreSQL migrations taking table locks while the app runs.
- Hints: transactions locking many rows (a missing index), tables without a primary key, long-open transactions.

For each pattern you get the cause in plain words, the evidence, and the code change (sorting keys, INSERT ... ON DUPLICATE KEY UPDATE or ON CONFLICT, locking the parent first, FOR NO KEY UPDATE, lock_timeout for migrations), plus a retry wrapper. It only reads the log files you give it; it never connects to a database.

## Requires

- Python 3.8+

## Known limitations

InnoDB logs only the current statement of each transaction, so earlier statements that took the first lock must be confirmed in the code. MySQL 5.7 doesn't print the locks held by transaction (1); they are inferred. Column names aren't in the log, and dates and decimals in keys stay as hex. PostgreSQL csvlog and jsonlog formats aren't parsed. It explains deadlocks; it doesn't diagnose plain lock-wait timeouts.

## Technical details

Python 3.8+ script using only the standard library, run by the AI agent in a terminal: scripts/deadlocks.py FILE... (or - for stdin). Input: SHOW ENGINE INNODB STATUS output, MySQL 5.7/8 error logs (prefixes and source-file suffixes are stripped), PostgreSQL stderr logs with any log_line_prefix, or application logs quoting the PostgreSQL error (JDBC, psycopg). Output: Markdown report grouped by pattern, or JSON with --json. Exit code 1 = deadlocks found, 2 = none found. Decodes InnoDB record fields (signed and unsigned integers, ASCII strings, supremum) and identifies records by space, page and heap number. Never connects to a database and writes nothing. references/fixes.md has the code patterns per cause. Works with any agent that can run Python, such as Claude Code, Codex or Cursor.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Database Deadlock Analyzer for MySQL and PostgreSQL skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What does Database Deadlock Analyzer for MySQL and PostgreSQL do?

Give it a MySQL or PostgreSQL deadlock log and get the rows involved, the pattern behind the deadlock and the code change that stops it.

### Which AI agents support Database Deadlock Analyzer for MySQL and PostgreSQL?

This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

### How do I use Database Deadlock Analyzer for MySQL and PostgreSQL?

Connect your AI agent to Agensi through MCP, then ask it to use Database Deadlock Analyzer for MySQL and PostgreSQL on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
