// PostgreSQL error reference

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
Error message
savepoint "before_update" does not exist

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 SAVEPOINT already ran, which removes that savepoint and any created after it.
  • ROLLBACK TO an 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

  1. 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;
  2. Create a savepoint again after rolling back to it if you need to return to that point a second time; ROLLBACK TO keeps the savepoint itself but RELEASE removes it.

Reproduce it safely

BEGIN;
ROLLBACK TO SAVEPOINT nope;  -- ERROR: savepoint "nope" does not exist
ROLLBACK;

Related errors

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.

// fewer errors, faster fixes

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.