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
-
Disk Pressure Production Incident Triage Prompt
Rapidly diagnose and mitigate a live disk-full / disk-pressure incident on a production host or node — reclaim space safely, keep the service up, and avoid the classic mistake of deleting the wrong thing under pressure.
-
Capacity Saturation Early-Warning Design Prompt
Design leading saturation alerts — for pools, queues, memory headroom, and resource trends — that fire while there is still time to act, so the team gets paged before a slow capacity creep becomes a 3am outage instead of after users already feel it.
-
Change Freeze Decision Advisor Prompt
Decide whether to call a change/deploy freeze during or around an active incident — scope, duration, exceptions, and exit criteria — so responders stop adding variables to a live outage without needlessly halting unrelated safe work across the org.
-
Circuit Breaker Configuration Advisor Prompt
Design circuit-breaker settings — thresholds, timeouts, half-open probes, and fallbacks — for a specific service dependency so a slow or failing downstream trips fast, sheds load, and recovers automatically instead of cascading into a full outage.
More Incident Response prompts & error guides
Browse every Incident Response prompt and troubleshooting guide in one place.
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.