↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / SQLSTATE

25P01 — no_active_sql_transaction

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.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Invalid Transaction State
condition name
no_active_sql_transaction
lang
en
sqlstate
25P01

Definition PG 18

25P01 — no_active_sql_transaction

At a glance {#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 {#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 {#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 {#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 {#messages}

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 {#observed}

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 {#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 {#versions}

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.

Related {#related}

25005 branch transaction no active SQL transaction, 25P02 failed SQL transaction, 25006 read-only SQL transaction.

Sources {#sources}

  • src.errcodes.18.6 (SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)
  • src.calls.REL_18_6 — raw/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)

Compare versions

SQLSTATE evidence and recorded runtime versions

cases · savepoint_without_transaction
{
  "assertions": [
    "SQLSTATE is 25P01",
    "SAVEPOINT outside a block reports the no-active-transaction message",
    "An explicit BEGIN/SAVEPOINT/RELEASE/COMMIT repair succeeds"
  ],
  "case_id": "savepoint_without_transaction",
  "cleanup": "Drop the case schema with an owner connection.",
  "has_snippet": true,
  "position": 0,
  "preconditions": [
    "A runner-owned disposable target is provisioned."
  ],
  "repair": "Follow the explicit transaction or source boundary described by the case.",
  "trigger": "Run SAVEPOINT without BEGIN, then repeat inside an explicit block.",
  "versions": [
    "10",
    "18"
  ]
}
claims · identity
{
  "claim_id": "identity",
  "limits": "It is distinct from the branch-transaction condition 25005.",
  "method": "Read the fixed condition row and macro.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "25P01 is no_active_sql_transaction in Class 25."
}
claims · savepoint-path
{
  "claim_id": "savepoint-path",
  "limits": "Other no-active paths may be WARNING or use a different statement name; this case uses the SAVEPOINT ERROR path.",
  "method": "Trace the SAVEPOINT state branch and compare the official savepoint boundary.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.xact.savepoint.18.6",
    "doc.savepoint.18.6",
    "src.calls.REL_18_6"
  ],
  "statement": "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."
}
claims · runtime
{
  "claim_id": "runtime",
  "limits": "The case covers SAVEPOINT outside a transaction block, not every warning or no-active path.",
  "method": "Read the selected summaries and structured diagnostics.",
  "position": 2,
  "runtime": [],
  "sources": [
    "runtime",
    "runtime.25P01-batch2-latest-20260909.latest",
    "runtime.25P01-batch2-pg10-20260909.pg10"
  ],
  "statement": "The selected SAVEPOINT case returned 25P01 on PostgreSQL 18.6 and 10.21, stayed IDLE in autocommit mode, and completed the explicit-block repair."
}
claims · warning-path
{
  "claim_id": "warning-path",
  "limits": "These warning/error paths are source-backed context, not the selected SAVEPOINT runtime case.",
  "method": "Read the resolved report groups at the no-transaction COMMIT/ROLLBACK and transaction-chain branches.",
  "position": 3,
  "runtime": [],
  "sources": [
    "src.xact.18.6",
    "src.calls.REL_18_6"
  ],
  "statement": "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."
}
messages · savepoint
{
  "limits": "The %s substitution is the statement name; the selected message is SAVEPOINT can only be used in transaction blocks.",
  "message_id": "savepoint",
  "path": "",
  "position": 0,
  "raw": {
    "id": "savepoint",
    "limits": "The %s substitution is the statement name; the selected message is SAVEPOINT can only be used in transaction blocks.",
    "primary_template": "%s can only be used in transaction blocks",
    "severity_source": "ERROR for the selected SAVEPOINT path; the shared dynamic form can be WARNING in other branches.",
    "sources": [
      "src.xact.savepoint.18.6"
    ],
    "sqlstate": "25P01"
  },
  "severity": "ERROR for the selected SAVEPOINT path; the shared dynamic form can be WARNING in other branches.",
  "sources": [
    "src.xact.savepoint.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "can only be used in transaction blocks",
      "position": 0,
      "role": "",
      "template": "%s can only be used in transaction blocks"
    }
  ]
}
messages · no-transaction-warning
{
  "limits": "Used by no-transaction COMMIT/ROLLBACK branches; it is not the selected SAVEPOINT ERROR.",
  "message_id": "no-transaction-warning",
  "path": "",
  "position": 1,
  "raw": {
    "id": "no-transaction-warning",
    "limits": "Used by no-transaction COMMIT/ROLLBACK branches; it is not the selected SAVEPOINT ERROR.",
    "primary_template": "there is no transaction in progress",
    "severity_source": "WARNING",
    "sources": [
      "src.xact.18.6"
    ],
    "sqlstate": "25P01"
  },
  "severity": "WARNING",
  "sources": [
    "src.xact.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "there is no transaction in progress",
      "position": 0,
      "role": "",
      "template": "there is no transaction in progress"
    }
  ]
}
runtimes · runtime.25P01-batch2-latest-20260909.latest · 18.6 (Homebrew) · passed
{
  "cases": [
    "savepoint_without_transaction"
  ],
  "limits": "",
  "position": 0,
  "raw": {
    "case_manifest": {
      "path": "verify/cases/25P01/cases.json",
      "sha256": "49bc7e60ade603e07255a3096b94803423aa3a2fbd058a3aca604d4edfaf0072"
    },
    "case_status": "passed",
    "cases": [
      "savepoint_without_transaction"
    ],
    "id": "runtime.25P01-batch2-latest-20260909.latest",
    "observed": {
      "after_begin": "INTRANS",
      "after_error": "IDLE",
      "final_status": "IDLE",
      "primary": "SAVEPOINT can only be used in transaction blocks",
      "sqlstate": "25P01"
    },
    "raw": "verify/results/25P01-batch2-latest-20260909/latest/raw.jsonl",
    "raw_sha256": "4bd89117ee074c9e6d7bc8fb0023b2dbea6cc2389c3e6956a4074b161ef0887a",
    "run_id": "25P01-batch2-latest-20260909",
    "server_version": "18.6 (Homebrew)",
    "server_version_num": 180006,
    "snippet_registry": {
      "path": "verify/cases/25P01/snippets.json",
      "sha256": "a1ffffc778f82789f1c1ac4027a109fc76e4b315ef2e3a5bdbfc47c8f84ce951"
    },
    "status": "passed",
    "summary": "verify/results/25P01-batch2-latest-20260909/latest/summary.json",
    "summary_sha256": "aa6294daccf84497125a2e823231f2f7f7c3909d16064761ae4e8d4783376027",
    "target": "latest",
    "target_status": "passed"
  },
  "run_id": "25P01-batch2-latest-20260909",
  "runtime_id": "runtime.25P01-batch2-latest-20260909.latest",
  "server_version": "18.6 (Homebrew)",
  "status": "passed",
  "target": "latest"
}
runtimes · runtime.25P01-batch2-pg10-20260909.pg10 · 10.21 (Debian 10.21-1.pgdg90+1) · passed
{
  "cases": [
    "savepoint_without_transaction"
  ],
  "limits": "",
  "position": 1,
  "raw": {
    "case_manifest": {
      "path": "verify/cases/25P01/cases.json",
      "sha256": "49bc7e60ade603e07255a3096b94803423aa3a2fbd058a3aca604d4edfaf0072"
    },
    "case_status": "passed",
    "cases": [
      "savepoint_without_transaction"
    ],
    "id": "runtime.25P01-batch2-pg10-20260909.pg10",
    "observed": {
      "after_begin": "INTRANS",
      "after_error": "IDLE",
      "final_status": "IDLE",
      "primary": "SAVEPOINT can only be used in transaction blocks",
      "sqlstate": "25P01"
    },
    "raw": "verify/results/25P01-batch2-pg10-20260909/pg10/raw.jsonl",
    "raw_sha256": "af9d34a18019d994852fe38933d1f000b0bd6f2536d63c41e6365ba8d8b26864",
    "run_id": "25P01-batch2-pg10-20260909",
    "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
    "server_version_num": 100021,
    "snippet_registry": {
      "path": "verify/cases/25P01/snippets.json",
      "sha256": "a1ffffc778f82789f1c1ac4027a109fc76e4b315ef2e3a5bdbfc47c8f84ce951"
    },
    "status": "passed",
    "summary": "verify/results/25P01-batch2-pg10-20260909/pg10/summary.json",
    "summary_sha256": "daa3bbb7722b859f4b759e3a8421138b6e5a38cf9d3037d32629daf4c923eda4",
    "target": "pg10",
    "target_status": "passed"
  },
  "run_id": "25P01-batch2-pg10-20260909",
  "runtime_id": "runtime.25P01-batch2-pg10-20260909.pg10",
  "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
  "status": "passed",
  "target": "pg10"
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt"
}
sources · src.calls.REL_18_6
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 1,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6",
  "tag": "",
  "url": ""
}
sources · src.xact.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/access/transam/xact.c",
  "position": 2,
  "sha256": "75b012c0b047d1dc905a30975c244beec366e45eac0dbf109fd21bcd611a8e39",
  "source_id": "src.xact.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/transam/xact.c#L3724-L3749"
}
sources · doc.savepoint.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "https://www.postgresql.org/docs/18/sql-savepoint.html",
  "kind": "upstream_source",
  "location": "",
  "path": "doc/src/sgml/ref/savepoint.sgml",
  "position": 3,
  "sha256": "aa6e167d373da6118249c87404a7b2ff8be8c7df790449814f1d9dc433bbd428",
  "source_id": "doc.savepoint.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/savepoint.sgml#L68-L78"
}
sources · src.xact.savepoint.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/access/transam/xact.c",
  "position": 4,
  "sha256": "75b012c0b047d1dc905a30975c244beec366e45eac0dbf109fd21bcd611a8e39",
  "source_id": "src.xact.savepoint.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/access/transam/xact.c#L4418-L4424"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:7b7c67ef57bb09f886f99d0fe9c3beb1b270f92d25a0bf4b595000f75ee51f7c

Text language: en · english-manuals:7b7c67ef57bb09f886f99d0fe9c3beb1b270f92d25a0bf4b595000f75ee51f7c