文档 / SQL 状态码 / Class 57 操作员干预
57P01 admin_shutdown
ERROR 已实测 详解 实测通过
- 条件名
admin_shutdown- 宏名称
ERRCODE_ADMIN_SHUTDOWN- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
57P01 表示服务器发起的管理 shutdown 条件。固定核心路径覆盖有序或立即终止客户端、worker/并行终止,以及同步复制等待;后者明确提示本地提交可能早于 standby 复制。
含义
同一 SQLSTATE 在多个生命周期边界复用,因此 severity 与恢复取决于调用点。立即停止信号路径发送 client-only WARNING 后退出,不运行正常清理;普通客户端管理员命令路径使用 FATAL。同步复制路径使用 WARNING,并带有 detail:The transaction has already committed locally, but might not have been replicated to the standby. 并行和 worker 路径各自使用 FATAL 或 worker 控制流。不能把这些路径互相替代为同一条“业务已提交/已回滚”结论。
消息
- 立即停止:primary
terminating connection due to immediate shutdown command,severity 为WARNING_CLIENT_ONLY;报告后进程退出。 - 客户端 backend 管理员命令:primary
terminating connection due to administrator command,severity 为 FATAL;连接关闭。 - 同步复制等待:primary
canceling the wait for synchronous replication and terminating connection due to administrator command,severity 为 WARNING,detail 为The transaction has already committed locally, but might not have been replicated to the standby.。 - 并行事务:primary
postmaster exited during a parallel transaction,severity 为 FATAL。 - 另一个固定 promotion 等待分支在 FATAL 下报告
terminating connection due to unexpected postmaster exit,context 为while waiting on promotion。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
terminating connection due to immediate shutdown command
terminating connection due to administrator command
canceling the wait for synchronous replication and terminating connection due to administrator command
The transaction has already committed locally, but might not have been replicated to the standby.
postmaster exited during a parallel transaction
terminating connection due to unexpected postmaster exit
while waiting on promotion
诊断
关联完整 primary/detail/context、backend PID、管理员或 postmaster 动作、服务器 shutdown/recovery 日志及事务边界。选定运行案例只覆盖客户端 backend 的管理员命令分支,不能证明立即停止、同步复制、worker、并行或 promotion 分支的结果。出现同步复制 detail 时,事务已经在本地提交,而 standby 是否收到仍不确定;该 WARNING 之后原连接仍会终止,不能在旧 session 恢复。重放非幂等操作前应查询持久化状态与复制状态。
处理
对 FATAL 或 client-only shutdown 报告,原连接不是事务恢复点:等待服务器 ready,建立新连接,并在重试前检查持久化业务状态或幂等键。同步复制分支要记录本地提交已经发生,并分别确认 standby 接收;WARNING 之后连接会终止,不能在旧 session 恢复。不能假定任何 57P01 路径都留下可用 session。已接受案例中的 fresh SELECT 1 只能证明终止目标后服务器可连接,不能证明中断的业务操作已提交。
可复现案例
在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。
admin_terminate_backend PG 10 / 18 有 SQL
前置条件
- A runner-owned disposable target is provisioned.
- The victim PID is obtained from the connection being terminated.
触发
Create a runner client session, terminate only its backend PID from a separate runner session, and reconnect.
断言
- The terminated backend reports SQLSTATE 57P01 and FATAL administrator-command text
- The selected PID is verified as a runner-created client backend and differs from the admin PID
- The victim connection closes after termination
- A fresh runner connection executes SELECT 1 successfully
处置
Treat the old connection as unusable after administrator termination; inspect the operation outcome and establish a fresh connection before continuing.
清理
Close all runner connections and drop the case schema with an owner connection.
实测诊断
选定注册表在 PostgreSQL 18.6 与 10.21 上分别创建 runner-owned victim client backend、不同的 admin session 和 fresh session。admin 核对目标身份,pg_terminate_backend 返回 true。victim 驱动收到 FATAL / 57P01 及 terminating connection due to administrator command 后断开;fresh session 返回 1 并处于 IDLE。这个有界案例不覆盖其他源码分支,也不证明业务提交结果。
代表案例
只能使用案例创建的 victim session 返回的 PID,不能替换为任意生产 PID 或 admin 自身 PID。fresh probe 验证的是定向终止后服务器可达。重放非幂等请求前检查持久化业务状态或幂等键。
-- 由案例运行器创建的 victim 会话
SELECT pg_backend_pid(); -- 保存为 :victim_pid
SELECT 1; -- 终止前探测
-- admin 会话:记录自身 PID,只使用运行器创建的 victim PID
SELECT pg_backend_pid(); -- 保存为 :admin_pid
SELECT pid, backend_type FROM pg_stat_activity WHERE pid = backend_pid;
SELECT pg_terminate_backend(backend_pid);
-- victim 断开后建立 fresh 会话
SELECT 1;
版本
锁定目录从 7.4 记录此条件;该目录边界不等于精确实现引入版本。固定源码覆盖 PostgreSQL 18.6,选定运行案例另在 PostgreSQL 10.21 观察到。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 435 行
- 上游源码 src/backend/tcop/postgres.c 第 2999 行
- 上游源码 src/backend/tcop/postgres.c 第 3354 行
- 上游源码 src/backend/replication/syncrep.c 第 302 行
- 上游源码 src/backend/access/transam/parallel.c 第 938 行
- 上游源码 src/backend/access/transam/xlogfuncs.c 第 737 行
- 核验材料 verify/cases/57P01/cases.json
- 核验材料 verify/results/ops-57p01-latest-2/latest/raw.jsonl
- 核验材料 verify/results/ops-57p01-pg10-1/pg10/raw.jsonl
- 核验材料 verify/results/ops-57p01-latest-2/latest/summary.json
- 核验材料 verify/results/ops-57p01-pg10-1/pg10/summary.json
- 核验材料 verify/cases/57P01/snippets.json
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
57P01 is admin_shutdown in SQLSTATE Class 57.
-
The cited PostgreSQL 18.6 source paths support the concrete phase, message, and lifecycle boundary described.
-
The locked catalogue records 57P01 from 7.4; that boundary does not prove exact implementation introduction.
-
The admin_terminate_backend case passed on PostgreSQL 18.6 and 10.21 with SQLSTATE, severity or disconnect outcome, recovery/repair, cleanup, and isolated-target stop assertions.
运行记录
| 目标 | 服务器版本 | 结果 | 覆盖案例 |
|---|---|---|---|
| latest | 18.6 (Homebrew) | passed | admin_terminate_backend |
| pg10 | 10.21 (Debian 10.21-1.pgdg90+1) | passed | admin_terminate_backend |
同类 SQL 状态码
| 状态码 | 条件名 | 宏名称 | 严重等级 | 版本 |
|---|---|---|---|---|
| 57000 | operator_intervention | ERRCODE_OPERATOR_INTERVENTION |
ERROR | 7.4 |
| 运维干预类别的通用条件,核心未见直接调用。 | 活跃 | |||
| 57014 | query_canceled | ERRCODE_QUERY_CANCELED |
ERROR | 7.4 |
| 语句被取消,含 statement_timeout 到期。 | 活跃 | |||
| 57P01 | admin_shutdown | ERRCODE_ADMIN_SHUTDOWN |
ERROR | 7.4 |
| 管理员关闭服务器或终止后端,会话被断开。 | 活跃 | |||
| 57P02 | crash_shutdown | ERRCODE_CRASH_SHUTDOWN |
ERROR | 7.4 |
| postmaster 因崩溃重启而令后端回滚退出。 | 活跃 | |||
| 57P03 | cannot_connect_now | ERRCODE_CANNOT_CONNECT_NOW |
ERROR | 7.4 |
| 服务器处于启动或恢复中,暂不接受连接。 | 活跃 | |||
| 57P04 | database_dropped | ERRCODE_DATABASE_DROPPED |
ERROR | 9.0 |
| 所连数据库被删除,恢复冲突终止了会话。 | 活跃 | |||
| 57P05 | idle_session_timeout | ERRCODE_IDLE_SESSION_TIMEOUT |
ERROR | 14 |
| 空闲会话超过 idle_session_timeout 被终止。 | 活跃 | |||