select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 25 · INVALID TRANSACTION STATE

no_active_sql_transaction

SQLSTATE
25P01
Condition name
no_active_sql_transaction
Class
Invalid Transaction State
Source macro
ERRCODE_NO_ACTIVE_SQL_TRANSACTION
Evidence
Observed at runtime in the source evidence
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>25P01 — no_active_sql_transaction</h1>

At a glance

25P01 reports that an operation needs an active SQL transaction. The selected case sends SAVEPOINT with autocommit enabled, receives the exact error while the session remains IDLE, then repeats the operation inside BEGIN and commits.

Meaning

The source formats the statement name into %s can only be used in transaction blocks; the selected SAVEPOINT path is an ERROR. The same SQLSTATE also has COMMIT AND CHAIN/ROLLBACK AND CHAIN errors and no-transaction COMMIT/ROLLBACK warnings with the fixed text there is no transaction in progress.

Diagnosis

Check whether the client is in an explicit block before issuing SAVEPOINT, RELEASE SAVEPOINT, or ROLLBACK TO SAVEPOINT. In the selected run, the failed autocommit statement leaves IDLE; the repair uses BEGIN, SAVEPOINT, RELEASE, and COMMIT.

Response

Start an explicit transaction before creating a savepoint. If the operation was sent without a block, correct the client transaction wrapper and retry the intended operation; no rollback is needed for this autocommit error because no open failed block remains.

Source message

xact.c formats %s can only be used in transaction blocks; this case substitutes SAVEPOINT with ERROR. COMMIT AND CHAIN and ROLLBACK AND CHAIN use the same dynamic form when no block exists, while no-transaction COMMIT/ROLLBACK use the WARNING text there is no transaction in progress.

Observed diagnostics

18.6 (Homebrew) / latest: SQLSTATE 25P01; primary SAVEPOINT can only be used in transaction blocks; after-error IDLE; explicit repair INTRANS → IDLE. 10.21 (Debian 10.21-1.pgdg90+1) / pg10: SQLSTATE 25P01; primary SAVEPOINT can only be used in transaction blocks; after-error IDLE; explicit repair INTRANS → IDLE.

Representative case

The runner reads the no-block SAVEPOINT and explicit-block repair statements below from the shared registry; complete assertions, environment, and cleanup are in case export.

-- trigger
SAVEPOINT outside_block;
-- begin
BEGIN;
-- savepoint
SAVEPOINT inside_block;
-- release
RELEASE SAVEPOINT inside_block;
-- commit
COMMIT;
-- verify
SELECT 1;

The SQLSTATE, diagnostics, states, and repair assertions for this excerpt come from the shared registry (SHA-256 a1ffffc778f82789f1c1ac4027a109fc76e4b315ef2e3a5bdbfc47c8f84ce951); structured evidence.

Authored evidence IDs: identity, savepoint-path, runtime. Selected runtime records: runtime.25P01-batch2-latest-20260909.latest, runtime.25P01-batch2-pg10-20260909.pg10.

Versions and limits

The SAVEPOINT case returns 25P01 with the same primary text on 18.6 and 10.21, and the explicit-block repair finishes IDLE on both.

Sources

  • src.errcodes.18.6 (SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)
  • src.calls.REL_18_6raw/calls/REL_18_6.jsonl (SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)
  • src.xact.18.6 (SHA-256 75b012c0b047d1dc905a30975c244beec366e45eac0dbf109fd21bcd611a8e39)
  • doc.savepoint.18.6 (SHA-256 aa6e167d373da6118249c87404a7b2ff8be8c7df790449814f1d9dc433bbd428) · official documentation
  • src.xact.savepoint.18.6 (SHA-256 75b012c0b047d1dc905a30975c244beec366e45eac0dbf109fd21bcd611a8e39)

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

25P01 is no_active_sql_transaction in Class 25.

Method: Read the fixed condition row and macro.

Limits: It is distinct from the branch-transaction condition 25005.

src.errcodes.18.6

The fixed xact.c paths report 25P01 when SAVEPOINT, RELEASE SAVEPOINT, or ROLLBACK TO SAVEPOINT is issued without an explicit transaction block; the selected SAVEPOINT path is ERROR.

Method: Trace the SAVEPOINT state branch and compare the official savepoint boundary.

Limits: Other no-active paths may be WARNING or use a different statement name; this case uses the SAVEPOINT ERROR path.

src.xact.savepoint.18.6 doc.savepoint.18.6 src.calls.REL_18_6

The selected SAVEPOINT case returned 25P01 on PostgreSQL 18.6 and 10.21, stayed IDLE in autocommit mode, and completed the explicit-block repair.

Method: Read the selected summaries and structured diagnostics.

Limits: The case covers SAVEPOINT outside a transaction block, not every warning or no-active path.

runtime runtime.25P01-batch2-latest-20260909.latest runtime.25P01-batch2-pg10-20260909.pg10

The fixed xact.c source also uses 25P01 for no-transaction COMMIT/ROLLBACK warnings with "there is no transaction in progress", while COMMIT AND CHAIN and ROLLBACK AND CHAIN use the transaction-block error form.

Method: Read the resolved report groups at the no-transaction COMMIT/ROLLBACK and transaction-chain branches.

Limits: These warning/error paths are source-backed context, not the selected SAVEPOINT runtime case.

src.xact.18.6 src.calls.REL_18_6

Message templates

ERROR for the selected SAVEPOINT path; the shared dynamic form can be WARNING in other branches. · savepoint

Primary

%s can only be used in transaction blocks

The %s substitution is the statement name; the selected message is SAVEPOINT can only be used in transaction blocks.

WARNING · no-transaction-warning

Primary

there is no transaction in progress

Used by no-transaction COMMIT/ROLLBACK branches; it is not the selected SAVEPOINT ERROR.

Reproduction & repair cases

savepoint_without_transaction · PG 10, 18

Preconditions

  • A runner-owned disposable target is provisioned.

Trigger: Run SAVEPOINT without BEGIN, then repeat inside an explicit block.

Expected assertions

  • SQLSTATE is 25P01
  • SAVEPOINT outside a block reports the no-active-transaction message
  • An explicit BEGIN/SAVEPOINT/RELEASE/COMMIT repair succeeds

Repair: Follow the explicit transaction or source boundary described by the case.

Cleanup: Drop the case schema with an owner connection.

Recorded runtime evidence

18.6 (Homebrew) · passed

Run: 25P01-batch2-latest-20260909

{
  "primary": "SAVEPOINT can only be used in transaction blocks",
  "sqlstate": "25P01",
  "after_begin": "INTRANS",
  "after_error": "IDLE",
  "final_status": "IDLE"
}
10.21 (Debian 10.21-1.pgdg90+1) · passed

Run: 25P01-batch2-pg10-20260909

{
  "primary": "SAVEPOINT can only be used in transaction blocks",
  "sqlstate": "25P01",
  "after_begin": "INTRANS",
  "after_error": "IDLE",
  "final_status": "IDLE"
}

Definition snapshot: english-manuals:93b4eb3983bcc330679d51972a6… · English manual source