↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

2D000 — invalid_transaction_termination(无效事务终止)

在过程或子事务上下文中无效地终止事务。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Invalid Transaction Termination
condition name
invalid_transaction_termination
lang
en
sqlstate
2D000

版本定义 PG 18

2D000 — invalid_transaction_termination(无效事务终止)

速览 {#at-a-glance}

2D000 是 SPI 在过程或子事务上下文尝试无效事务终止时使用的保护码。18.6 固定路径把它与正常显式 COMMIT 区分开来;本批不把所有过程级事务错误都归为 2D000,也不使用 RAISE 伪造 SQL 案例。

含义 {#meaning}

2D000 是 SPI 的事务终止无效条件。固定 spi.c 路径在原子 SPI 上下文中拒绝 SPI_commit/SPI_rollback,并在子事务活动时分别拒绝提交或回滚。源码注释明确把限制与过程语言用子事务实现异常块联系起来。

诊断 {#diagnosis}

定位尝试控制事务的过程/函数和 SPI 调用者。区分允许控制事务的顶层 CALL 与原子 SPI 上下文中的函数或异常块,并检查是否仍处于嵌套子事务。固定源码报文包括 invalid transaction termination、cannot commit while a subtransaction is active、cannot roll back while a subtransaction is active;普通客户端 COMMIT 错误不能单独归类为这条路径。

处理 {#response}

把事务控制移到允许的过程边界,或先让外层过程/异常块结束活动子事务,再终止顶层事务。不要在同一禁止的 SPI 上下文里再次发送 COMMIT/ROLLBACK,也不要套用通用重试。本批只记录源码路径,不用 RAISE 或不忠实的 SQL 伪造运行案例。

版本 {#versions}

上面的锁定事实表记录项目快照范围内的目录存在情况。固定源码证据只覆盖下面声明的路径;不能仅从定义推导精确行为引入版本或更广的运行覆盖。

相关 {#related}

在改变过程或事务边界前,可先对照25P01 无活动 SQL 事务和24000 游标状态无效。

来源 {#sources}

  • src.errcodes.18.6(SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)
  • 源码路径(SHA-256 7244b45f632583c72530832df901b788fe403c8857425dd13edb49d9f84b0c78)

比较版本

SQLSTATE 证据与已记录的运行版本

cases · invalid_transaction_termination_boundary
{
  "assertions": [],
  "case_id": "invalid_transaction_termination_boundary",
  "cleanup": "Drop the case schema with an owner connection.",
  "has_snippet": false,
  "position": 0,
  "preconditions": [
    "A runner-owned disposable target is provisioned."
  ],
  "repair": "Keep transaction control at the procedure boundary supported by the server; do not add COMMIT/ROLLBACK inside a context that forbids termination.",
  "trigger": "No generic SQL-only transaction-termination case is executed; the fixed SPI procedure/subtransaction guard is recorded as a source boundary.",
  "versions": [
    "10",
    "18"
  ]
}
claims · identity
{
  "claim_id": "identity",
  "limits": "This records the protocol definition and does not imply a natural PostgreSQL throw path.",
  "method": "Read the fixed errcodes.txt row and macro mapping.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "2D000 is the invalid_transaction_termination condition in Class 2D."
}
claims · source-boundary
{
  "claim_id": "source-boundary",
  "limits": "No representative runtime case is claimed; the path requires a specialized internal or trigger/procedure context.",
  "method": "Trace the fixed source call scan and classify the path before selecting a safe runner case.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.spi.18.6",
    "src.calls.REL_18_6"
  ],
  "statement": "invalid transaction termination is a source-confirmed path for 2D000."
}
messages · message.invalid-transaction-termination
{
  "limits": "The same source path also emits more specific subtransaction messages.",
  "message_id": "message.invalid-transaction-termination",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.invalid-transaction-termination",
    "limits": "The same source path also emits more specific subtransaction messages.",
    "primary_template": "invalid transaction termination",
    "severity_source": "ERROR",
    "sources": [
      "src.spi.18.6"
    ],
    "sqlstate": "2D000"
  },
  "severity": "ERROR",
  "sources": [
    "src.spi.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "invalid transaction termination",
      "position": 0,
      "role": "",
      "template": "invalid transaction termination"
    }
  ]
}
messages · message.commit-subtransaction
{
  "limits": "Only the active-subtransaction branch uses this wording.",
  "message_id": "message.commit-subtransaction",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.commit-subtransaction",
    "limits": "Only the active-subtransaction branch uses this wording.",
    "primary_template": "cannot commit while a subtransaction is active",
    "severity_source": "ERROR",
    "sources": [
      "src.spi.18.6"
    ],
    "sqlstate": "2D000"
  },
  "severity": "ERROR",
  "sources": [
    "src.spi.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot commit while a subtransaction is active",
      "position": 0,
      "role": "",
      "template": "cannot commit while a subtransaction is active"
    }
  ]
}
messages · message.rollback-subtransaction
{
  "limits": "Only the active-subtransaction rollback branch uses this wording.",
  "message_id": "message.rollback-subtransaction",
  "path": "",
  "position": 2,
  "raw": {
    "id": "message.rollback-subtransaction",
    "limits": "Only the active-subtransaction rollback branch uses this wording.",
    "primary_template": "cannot roll back while a subtransaction is active",
    "severity_source": "ERROR",
    "sources": [
      "src.spi.18.6"
    ],
    "sqlstate": "2D000"
  },
  "severity": "ERROR",
  "sources": [
    "src.spi.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot roll back while a subtransaction is active",
      "position": 0,
      "role": "",
      "template": "cannot roll back while a subtransaction is active"
    }
  ]
}
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.spi.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/spi.c",
  "position": 2,
  "sha256": "7244b45f632583c72530832df901b788fe403c8857425dd13edb49d9f84b0c78",
  "source_id": "src.spi.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/spi.c#L239-L241"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:bb1bd49aea8db88a3121a25e083d1af478858ce5bcdd7dec1550c4b62bcf6157

正文语言: zh-Hans · english-manuals:bb1bd49aea8db88a3121a25e083d1af478858ce5bcdd7dec1550c4b62bcf6157