Track down and prevent database deadlocks
Prompt that reads a deadlock report, finds the conflicting lock order and proposes lasting fixes. Paste it into an AI tool of your choice, which then resolves the deadlock.
- Topic
- Apps & prototypes
- Type
- Prompt
- Level
- Intermediate
- Time
- about 15 min
Results depend on the tool, the model and what you enter.
Result preview
Example: written by our editors, not real AI output.
Timeline: 1. Job A locks order 17, then wants stock row 5 2. Request B locks stock row 5, then wants order 17 3. Database aborts B Cause: opposite lock order Fix 1: always lock order before stock Fix 2: index on stock.product_id Fix 3: retry B up to 3 times with short random wait
Fill in
What you type stays in this browser window. We store and send nothing.
- PostgreSQL
- MySQL with InnoDB
- SQL Server
- a managed cloud database
- not sure
- two jobs update the same orders
- under high load at month end
- during a nightly import
- when users save at the same time
- after a new index was added
- aborted requests with an error
- jobs that retry endlessly
- slow pages during peaks
- missing updates
- only warnings in the log
Your prompt
You have edited the prompt. Changes in the fields above no longer overwrite it.
This is an instruction for an AI, not the result itself.
Where this prompt works
These AI tools are a good fit for this prompt:
How to use it
- Fill in the fields or tap a suggestion. Leave out names, addresses and other personal data.
- Copy the finished prompt into an AI tool of your choice.
- Paste the deadlock report from the database log and the queries of both code paths, with table names kept and customer data removed.
Why does this work?
A deadlock is rarely bad luck. It nearly always comes from two code paths that lock the same things in a different order, and a fixed order removes it for good.
Tips
- Test changes to transactions and indexes on a copy of the database before they go live.