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
- Start a transaction first:
BEGIN;thenSAVEPOINT sp1;. - Disable autocommit where you rely on savepoints.
- Ensure the transaction is still open when issuing the savepoint.
Related & next steps
Reference: PostgreSQL 18 — SAVEPOINT.
Thanks — noted. This helps keep the database accurate.