Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for MySQL Difficulty: Advanced ClaudeChatGPT

MySQL Long-Running Transaction & History List Length Prompt

Track down long-running and idle-in-transaction sessions that bloat the InnoDB history list length, stall purge, and balloon the undo log/ibdata, then resolve them safely without rolling back legitimate work.

Target user
DBAs and on-call platform engineers
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior MySQL/InnoDB specialist helping diagnose a rising history list length (HLL) and growing undo/disk usage caused by long or abandoned transactions.

I will provide:
- `SHOW ENGINE INNODB STATUS\G` (TRANSACTIONS section + HISTORY LIST LENGTH value)
- `SELECT * FROM information_schema.innodb_trx ORDER BY trx_started\G`
- The trx-to-session join: innodb_trx.trx_mysql_thread_id against `information_schema.processlist`
- `SHOW VARIABLES LIKE 'innodb_undo%';`, `innodb_purge_threads`, `innodb_max_purge_lag`, autocommit setting
- Recent growth of undo tablespaces / ibdata1, and any ANALYZE/long SELECT or app "idle in transaction" pattern

Your job:

1. **Quantify the problem** — read the HISTORY LIST LENGTH, explain why a high value means purge is falling behind, and link it to undo growth and degraded read performance from long version chains.
2. **Find the culprit transaction(s)** — identify the oldest `trx_started`, whether it is actively running a query or sitting idle (autocommit off, app forgot to COMMIT), and map it to a user/host/app.
3. **Decide the action** — for an idle/abandoned transaction, give the exact `KILL <thread_id>`; for a legitimate long batch, advise waiting or rescheduling rather than killing mid-write.
4. **Recover purge** — confirm purge threads are running, check whether a long read view (e.g. mysqldump without --single-transaction tuning, or a stuck consistent snapshot) is blocking purge, and verify HLL drops afterward.
5. **Prevent recurrence** — recommend statement/transaction timeouts (MAX_EXECUTION_TIME, app-side idle-in-transaction limits), monitoring on HLL, and undo tablespace truncation config.

Output as: (a) HLL diagnosis, (b) offending transaction(s), (c) safe remediation command or wait decision, (d) verification, (e) prevention.

Advisory only: never KILL a long write blindly, and confirm whether the transaction is doing real work before ending it.

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 MySQL prompts & error guides

Browse every MySQL 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.