选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 2D 事务终止无效

2D000 invalid_transaction_termination

无效事务终止

ERROR 源码确认 参考 未实测

类别
Class 2D 事务终止无效
严重等级
ERROR
条件名
invalid_transaction_termination
宏名称
ERRCODE_INVALID_TRANSACTION_TERMINATION
启用版本
7.4
状态
活跃

版本覆盖

速览

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

含义

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

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 invalid transaction termination

来源:src/backend/executor/spi.c @ REL_18_6

适用范围:The same source path also emits more specific subtransaction messages.

主消息 cannot commit while a subtransaction is active

来源:src/backend/executor/spi.c @ REL_18_6

适用范围:Only the active-subtransaction branch uses this wording.

主消息 cannot roll back while a subtransaction is active

来源:src/backend/executor/spi.c @ REL_18_6

适用范围:Only the active-subtransaction rollback branch uses this wording.

诊断

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

处理

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

可复现案例

在一次性实例上执行过的场景。

invalid_transaction_termination_boundary PG 10 / 18

前置条件

  • A runner-owned disposable target is provisioned.

触发

No generic SQL-only transaction-termination case is executed; the fixed SPI procedure/subtransaction guard is recorded as a source boundary.

处置

Keep transaction control at the procedure boundary supported by the server; do not add COMMIT/ROLLBACK inside a context that forbids termination.

清理

Drop the case schema with an owner connection.

版本

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

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 2D000 is the invalid_transaction_termination condition in Class 2D.

    核实方式Read the fixed errcodes.txt row and macro mapping.

    不覆盖This records the protocol definition and does not imply a natural PostgreSQL throw path.

    来源src/backend/utils/errcodes.txt

  • invalid transaction termination is a source-confirmed path for 2D000.

    核实方式Trace the fixed source call scan and classify the path before selecting a safe runner case.

    不覆盖No representative runtime case is claimed; the path requires a specialized internal or trigger/procedure context.

    来源src/backend/executor/spi.c · raw/calls/REL_18_6.jsonl