25P01 — 没有活动 SQL 事务(no_active_sql_transaction)
操作需要活动事务块,如自动提交下的 SAVEPOINT。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Invalid Transaction State
- condition name
- no_active_sql_transaction
- lang
- en
- sqlstate
- 25P01
版本定义 PG 18
25P01 — 没有活动 SQL 事务(no_active_sql_transaction)
速览 {#at-a-glance}
25P01 表示操作需要活动 SQL 事务。选定案例在自动提交会话中发送 SAVEPOINT,得到精确错误且会话保持 IDLE;随后在 BEGIN 内重新执行并提交。
含义 {#meaning}
源码把语句名填入 %s can only be used in transaction blocks;本文的 SAVEPOINT 路径严重级别为 ERROR。同一 SQLSTATE 还覆盖 COMMIT AND CHAIN/ROLLBACK AND CHAIN 的错误,以及无事务时 COMMIT/ROLLBACK 的警告,固定报文是 there is no transaction in progress。
诊断 {#diagnosis}
执行 SAVEPOINT、RELEASE SAVEPOINT 或 ROLLBACK TO SAVEPOINT 前,先确认客户端已进入显式事务块。选定运行中失败的自动提交语句后仍为 IDLE;修复序列是 BEGIN、SAVEPOINT、RELEASE、COMMIT。
处理 {#response}
创建保存点前先启动显式事务。若操作误发在事务块外,应修正客户端事务包装后重试;本自动提交错误没有遗留失败事务块,因此不需要回滚。
源码报文 {#messages}
xact.c 用 %s can only be used in transaction blocks 组装语句级报文;本案例把 %s 替换为 SAVEPOINT,严重级别为 ERROR。COMMIT AND CHAIN 与 ROLLBACK AND CHAIN 在无事务块时使用同一动态形式;无事务时的 COMMIT/ROLLBACK 则使用 WARNING 报文 there is no transaction in progress。
实测诊断 {#observed}
18.6 (Homebrew) / latest:SQLSTATE 25P01;主报文 SAVEPOINT can only be used in transaction blocks;错误后状态 IDLE;显式事务修复 INTRANS → IDLE。
10.21 (Debian 10.21-1.pgdg90+1) / pg10:SQLSTATE 25P01;主报文 SAVEPOINT can only be used in transaction blocks;错误后状态 IDLE;显式事务修复 INTRANS → IDLE。
代表案例 {#case}
运行器从共享语句清单(registry)读取下列无事务保存点和显式块修复语句;完整断言、环境和清理见 案例导出。
-- trigger
SAVEPOINT outside_block;
-- begin
BEGIN;
-- savepoint
SAVEPOINT inside_block;
-- release
RELEASE SAVEPOINT inside_block;
-- commit
COMMIT;
-- verify
SELECT 1;
上述片段的 SQLSTATE、诊断、状态和修复断言来自共享语句清单(registry)(SHA-256 a1ffffc778f82789f1c1ac4027a109fc76e4b315ef2e3a5bdbfc47c8f84ce951);结构化证据。
作者证据 ID:identity, savepoint-path, runtime。选定运行记录:runtime.25P01-batch2-latest-20260909.latest, runtime.25P01-batch2-pg10-20260909.pg10。
版本与边界 {#versions}
SAVEPOINT 案例在 18.6 与 10.21 返回相同主报文的 25P01,显式事务块修复后两个目标均回到 IDLE。
相关 {#related}
25005 分支事务没有活动 SQL 事务、25P02 失败 SQL 事务、25006 只读 SQL 事务。
来源 {#sources}
src.errcodes.18.6(SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)src.calls.REL_18_6—raw/calls/REL_18_6.jsonl(SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)src.xact.18.6(SHA-25675b012c0b047d1dc905a30975c244beec366e45eac0dbf109fd21bcd611a8e39)doc.savepoint.18.6(SHA-256aa6e167d373da6118249c87404a7b2ff8be8c7df790449814f1d9dc433bbd428) · official documentationsrc.xact.savepoint.18.6(SHA-25675b012c0b047d1dc905a30975c244beec366e45eac0dbf109fd21bcd611a8e39)
比较版本
SQLSTATE 证据与已记录的运行版本
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"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:7b7c67ef57bb09f886f99d0fe9c3beb1b270f92d25a0bf4b595000f75ee51f7c
正文语言: zh-Hans · english-manuals:7b7c67ef57bb09f886f99d0fe9c3beb1b270f92d25a0bf4b595000f75ee51f7c