Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Incident Response Difficulty: Advanced ClaudeChatGPTCursor

Database Lock Contention Incident Diagnosis Prompt

Diagnose a live production incident where database lock contention, long-running transactions, or deadlocks are stalling queries and cascading into application timeouts — and decide what to safely kill or roll back without corrupting data.

Target user
On-call SREs and DBAs triaging a live database contention or deadlock incident
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior SRE with deep database operations experience, running a live incident where queries are piling up, connections are saturating, and application requests are timing out — and the suspected cause is lock contention, a long-running transaction, or a deadlock storm. You know that killing the wrong query or transaction can leave data inconsistent or make things worse, so you move deliberately even under pressure. Walk me through diagnosis and safe mitigation.

I will provide:
- The database engine and version (Postgres, MySQL/InnoDB, etc.) and its role
- Symptoms: query latency, connection pool exhaustion, timeouts, deadlock errors in logs
- Any output I can gather (active queries, lock waits, blocking chains)
- Recent changes: deploys, migrations, batch jobs, traffic shifts

Your job:

1. **Confirm it is contention, not capacity** — how to distinguish lock waits from CPU/IO saturation or a connection-pool exhaustion downstream effect. Give the specific queries (`pg_stat_activity` + `pg_locks` blocking-chain query for Postgres; `INNODB_TRX` / `data_locks` / `SHOW ENGINE INNODB STATUS` for MySQL) and what to look for.

2. **Find the blocker** — identify the head-of-line blocking transaction: the oldest/longest transaction holding locks that everyone else waits on. Show me how to trace the blocking tree from waiters back to the root blocker, and how to see what statement and client it is.

3. **Understand the trigger** — map the likely cause: a long-running migration or `ALTER TABLE` taking a heavy lock, a stuck transaction left open by an app bug (`idle in transaction`), a hot-row update pattern, a batch job, or a deadlock cycle from inconsistent lock ordering.

4. **Decide the mitigation** — for each cause, the safest mitigation and its risk: cancel a query vs terminate a backend/connection, pause or kill a runaway batch/migration, raise or lower lock timeouts, or shed the app traffic causing the hot path. State clearly when killing a transaction risks a long rollback or partial write, and how to check that first.

5. **The idle-in-transaction trap** — how to detect and safely clear transactions an application opened and never committed, and why an app-side fix (or a `idle_in_transaction_session_timeout`) is the real fix.

6. **Verify recovery** — confirm the blocking chain has cleared, latency and connection counts recovered, and no data was left inconsistent by anything you terminated.

7. **Prevent recurrence** — the follow-ups: statement/lock timeouts, online/lock-light migration tooling, consistent lock ordering to avoid deadlocks, monitoring for long-running and idle-in-transaction sessions, and connection-pool sizing.

Output as: (a) a diagnosis runbook with the exact queries for my engine, (b) a blocking-tree interpretation guide, (c) a mitigation decision table (cause → safest action → risk → how to verify safe), (d) recovery verification steps, (e) prevention follow-ups.

Bias toward: identifying the single root blocker before killing anything, choosing the least-destructive mitigation, checking rollback cost before terminating a long transaction, and fixing the app-side pattern over repeatedly killing sessions.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Incident Response prompts & error guides

Browse every Incident Response prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.