Transaction Rollback on Error
Error message
current transaction is aborted, commands ignored until end of transaction block
Quick summary
An earlier statement in your transaction failed. The transaction is now in an aborted state and will not execute any more commands until you ROLLBACK.
Why this happens
A statement in the transaction failed (constraint violation, syntax error, etc.)
The application continued sending commands after the failure without rolling back
Not checking for errors after each statement in a transaction
Minimal example
BEGIN;
INSERT INTO orders (id, user_id) VALUES (1, 999); -- fails: user 999 doesn't exist
UPDATE users SET last_order = NOW() WHERE id = 999; -- ignored: transaction is aborted
COMMIT;BEGIN;
INSERT INTO orders (id, user_id) VALUES (1, 999); -- fails
ROLLBACK; -- roll back and start fresh
-- Fix the root cause, then retry in a new transactionAfter the first statement fails, you must ROLLBACK before running any more commands. Rolling back clears the aborted state.
How to diagnose
Check the error that preceded this message — that is the real cause
Review the transaction's statement sequence to find the failing statement
Ensure your application checks for errors after each statement
How to fix
Roll back the transaction:
ROLLBACKFix the statement that caused the original error
Start a new transaction and retry
Use SAVEPOINTs to partially recover within a transaction
How to prevent
Check for errors after every statement in a transaction
Roll back immediately when a statement fails
Use savepoints if you need to recover from partial failures
Use a transaction wrapper that auto-rolls-back on error
Related Resources
Related Glossary
Related Lessons
- Transactions
Learn about transaction error handling.