SQLSTATE 25P01 ERROR Class 25: Invalid Transaction State

no_active_sql_transaction SAVEPOINT can only be used in transaction blocks — 25P01

PostgreSQL error "SAVEPOINT can only be used in transaction blocks" (SQLSTATE 25P01): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A SAVEPOINT was issued outside an explicit transaction block. Savepoints require an open transaction, so PostgreSQL raises SQLSTATE 25P01 (no_active_sql_transaction).

  • SAVEPOINT used in autocommit mode with no BEGIN.
  • Savepoints only exist inside a transaction.
  • Common when the surrounding BEGIN is missing.

What the server log shows

ERROR:  SAVEPOINT can only be used in transaction blocks

Why PostgreSQL raises this — what the manual says

the SAVEPOINT reference (Description):

“Savepoints can only be established when inside a transaction block.”

A savepoint marks a rollback point within a transaction. With no open transaction (autocommit), there is nothing to mark, so PostgreSQL rejects it with 25P01.

Common causes

  • Issuing SAVEPOINT without a preceding BEGIN.
  • Running in autocommit mode.
  • A lost/implicit commit between BEGIN and SAVEPOINT.

How to fix it

  1. Start a transaction first: BEGIN; then SAVEPOINT sp1;.
  2. Disable autocommit where you rely on savepoints.
  3. Ensure the transaction is still open when issuing the savepoint.

Related & next steps

Reference: PostgreSQL 18 — SAVEPOINT.

Was this helpful?