57P04 — database_dropped
57P04
速览
57P04 在 recovery conflict 因当前连接所在数据库必须被删除而终止 session 时选用。同一 recovery-conflict primary 也用于其他冲突原因,但那些分支选择 40001;这里决定条件身份的是 database-dropped guard。
| 字段 | 值 |
|---|---|
| SQLSTATE | 57P04 |
| 条件名 | database_dropped |
| 状态 | 有效 |
| 已知存在于 | 9.0.4 |
| 锁定快照 | 9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3 |
| 宏 | ERRCODE_DATABASE_DROPPED |
| 别名 | — |
含义
固定调用点以 FATAL 发出 primary terminating connection due to conflict with recovery、动态 recovery-conflict detail 以及 hint In a moment you should be able to reconnect to the database and repeat your command.。SQLSTATE 表达式是明确的:只有 reason == PROCSIG_RECOVERY_CONFLICT_DATABASE 时选择 ERRCODE_DATABASE_DROPPED;同一终止分支的其他 reason 选择 ERRCODE_T_R_SERIALIZATION_FAILURE。数据库分支的 detail 是 User was connected to a database that must be dropped.。
消息
- primary:
terminating connection due to conflict with recovery,FATAL。 - 数据库删除 detail:
User was connected to a database that must be dropped.。 - hint:
In a moment you should be able to reconnect to the database and repeat your command.。 - 其他 recovery-conflict reason 可能复用相同 primary,但选择
40001和不同 detail;不能只凭 primary 把它们标成57P04。
诊断
保留 SQLSTATE、primary/detail/hint、数据库名、backend PID、recovery-conflict reason 及 standby/recovery 日志。确认 detail 指向被删除的数据库后,才按 57P04 处理。FATAL 报告会关闭连接,因此没有可发送 ROLLBACK 的 session。断开前中断的操作是否已提交,需要单独核对。
处理
等待 recovery conflict/数据库转换结束,连接到有效数据库,并在重放非幂等操作前核对持久化业务状态。若服务器返回带 40001 的其他 recovery-conflict detail,应使用 serialization/retry 处理。数据库仍在删除或 recovery 日志表明冲突活跃时,不要盲目反复重连。
版本
锁定目录从 9.0.4 记录此条件;该目录边界不等于精确实现引入版本。固定源码覆盖 PostgreSQL 18.6。
相关
来源
src/backend/tcop/postgres.c#L3233-3248
src/backend/tcop/postgres.c#L2549-2578
结构化证据记录保存 SQLSTATE guard、动态 detail 及源码/运行范围。