PostgreSQL 3B001: invalid savepoint specification
ROLLBACK TO SAVEPOINT or RELEASE named a savepoint that doesn't exist in the current transaction, often because it was already released or never set.
- SQLSTATE
3B001- Name
invalid_savepoint_specification- Category
- Savepoint Exception
What it means
Savepoints mark a point inside a transaction you can roll back to. 3B001 means the name in ROLLBACK TO SAVEPOINT or RELEASE SAVEPOINT doesn't match an active savepoint: it was never created, it was released, or a rollback to an earlier savepoint discarded it.
Savepoints only exist inside a transaction block. Outside one, the command fails with a different error (can only be used in transaction blocks, 25P01).
Common causes
- A typo in the savepoint name.
RELEASE SAVEPOINTalready ran, which removes that savepoint and any created after it.ROLLBACK TOan earlier savepoint, which destroys the savepoints created after it.- Autocommit is on, so each statement is its own transaction and the savepoint vanished when the statement ended.
How to fix it
-
Run the whole sequence inside one transaction, with matching names.
BEGIN; SAVEPOINT before_update; UPDATE accounts SET balance = balance - 100 WHERE id = 1; ROLLBACK TO SAVEPOINT before_update; COMMIT;
-
Create a savepoint again after rolling back to it if you need to return to that point a second time;
ROLLBACK TOkeeps the savepoint itself butRELEASEremoves it.
Reproduce it safely
BEGIN; ROLLBACK TO SAVEPOINT nope; -- ERROR: savepoint "nope" does not exist ROLLBACK;
Related errors
25P02current transaction is aborted2D000invalid transaction termination6401SQL Server: No transaction or savepoint found
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.