Diagnostic Queries
Symptoms
A ROLLBACK TO SAVEPOINT or RELEASE SAVEPOINT named a savepoint that does not exist in the current transaction. PostgreSQL raises SQLSTATE 3B001 (invalid_savepoint_specification).
- The named savepoint was never established or was already released.
- Common after a typo or releasing a savepoint earlier.
- Savepoints are scoped to the current transaction.
What the server log shows
ERROR: savepoint "sp1" does not exist
Why PostgreSQL raises this — what the manual says
the ROLLBACK TO SAVEPOINT reference (Notes):
“Specifying a savepoint name that has not been established is an error.”
Savepoints live within the current transaction. Referencing a name that was never set (or already released/rolled past) cannot be resolved, so PostgreSQL reports 3B001.
Common causes
- A typo in the savepoint name.
- The savepoint was already released.
- Referencing a savepoint from a different transaction.
How to fix it
- Establish the savepoint with
SAVEPOINT sp1;before referencing it. - Match the savepoint name exactly.
- Track active savepoints in application logic to avoid releasing too early.
Related & next steps
Reference: PostgreSQL 18 — ROLLBACK TO SAVEPOINT.
Thanks — noted. This helps keep the database accurate.