08006 — 连接失败(connection_failure)
与服务器的连接在会话中途失败。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Connection Exception
- condition name
- connection_failure
- lang
- en
- sqlstate
- 08006
版本定义 PG 18
08006 — 连接失败
速览 {#at-a-glance}
SQLSTATE 08006 是 Class 08 中的 connection_failure。08006 表示已有连接发生故障。固定路径包括 postgres_fdw 的取消/连接丢失处理以及 COPY 失败处理;它们没有一个适用于所有路径的主报文或严重级别,本批也有意不做普通 socket 的伪案例。
含义 {#meaning}
固定源码路径说明了为什么本类没有统一报文。在 postgres_fdw 中,取消请求失败时,在处理已有外部连接的过程中发出 WARNING;这是取消路径的诊断,本身不证明客户端会话已经终止。在 COPY 路径中,带有未完成事务的客户端 EOF 以 ERROR 报告,而较旧的 COPY-to-stdout 路径在输出连接丢失时以 FATAL 报告。严重级别和发生阶段都是含义的一部分,不能把它们合并成“socket 断了”。
ERROR 分支若发生在显式事务中,仍连接着的会话可能进入 INERROR,调用者应先 ROLLBACK 或回到合适的保存点再执行无关 SQL。FATAL 分支会结束后端连接,不存在可以发送 ROLLBACK 的会话。已经读到 EOF 的客户端也可能根本没有 SQLSTATE。这里的证据确认这些源码分支,但没有声称每次普通网络断开都会发出 08006。
分支指引 {#scenarios}
| 固定分支 | 它说明什么 | 首先检查什么 |
| --- | --- | --- |
| postgres_fdw 取消 WARNING | 已建立的外部连接上,取消请求无法发送或无法读取结果。 | 保留动态 libpq 文本、FDW 操作和本地事务状态;WARNING 本身不说明本地会话已关闭。 |
| COPY 客户端 EOF ERROR | 服务器在 COPY 相关连接仍有未完成事务时检测到 EOF。 | 触发该分支的客户端 socket 已经到达 EOF,不能在其上发送 ROLLBACK 或复用;应重新连接并核对 COPY 结果。 |
| COPY-to-stdout FATAL | 固定的 10.23 路径在 COPY 期间丢失输出连接,并使用 fatal 级别。 | 丢弃后端连接并核对已经发送或接收的数据;不能执行会话级回滚。 |
| 普通客户端 EOF | 对端在固定服务器分支之外消失。 | 结合驱动/socket 和服务器日志;不要仅凭客户端 null SQLSTATE 指定 08006。 |
诊断 {#diagnosis}
关联后端 PID、操作、服务器日志字段和客户端异常。客户端断 socket 可能得到 null SQLSTATE,而服务器端 FDW 或 COPY 路径可能发出带路径特定文本的 08006。决定是否重试前,区分 08001(尚未建立连接)、08007/40003(完成结果不确定)和语句尚未执行成功的普通错误。
要同时检查严重级别和生命周期。WARNING 表示 FDW 取消分支中本地会话可能仍然存活;ERROR 要检查 INERROR 还是 IDLE,必要时恢复事务;FATAL 表示后端已消失。如果客户端在 ErrorResponse 之前只读到 EOF,没有 SQLSTATE 是线路交换丢失的正常证据,不能据此认定 08006。
处理 {#response}
丢弃连接池标记为损坏的连接,核对远端或非幂等操作的结果,并在明确幂等策略后重试完整操作。本页只确认固定源码边界;没有用 RAISE、超时或普通断 socket 冒充实测 08006。
对另一个仍保持连接的 ERROR 情形,应先回滚失败的显式事务(或回滚到围绕该操作有意建立的保存点),再决定能否重试完整操作。这个一般事务规则不能证明 COPY 客户端 EOF socket 可复用:源码分支已经检测到该客户端连接的 EOF。FATAL 或已经丢失的 socket 则要建立新会话,并在任何重放前核对结果。自动提交不会让远端或 COPY 操作自动具备幂等性,它只改变本地事务边界。
报文 {#messages}
固定分支包含以下不同诊断:
postgres_fdw取消路径的WARNING:could not send cancel request: %s,其中 libpq 错误文本是动态值。- 同一 FDW 路径的
WARNING:could not get result of cancel request: %s,返回的连接错误文本是动态值。 - 固定 10.23 COPY 路径的
FATAL:connection lost during COPY to stdout。 - 固定 18.6/10.23 COPY 客户端 EOF 路径的
ERROR:unexpected EOF on client connection with an open transaction。
证据将这些变体分开记录;普通客户端断 socket 得到的 null SQLSTATE 不能被提升为 08006。
即使报文都提到连接,ERROR 与 FATAL 也有不同的恢复契约。COPY 客户端 EOF 的 ERROR 分支检测到客户端 socket 已经消失;它不建立可复用 socket,也不提供在该连接上发送 ROLLBACK 的路径。后者属于 COPY-to-stdout 路径,会关闭后端。本批没有自然 08006 运行,因此这些差异来自固定源码路径和文档规定的事务边界,而不是合成的 socket 实验。
代表案例 {#case}
本页没有选定的自然 SQL 运行。结构化证据记录的是源码或定义边界;客户端 RAISE 不能代表服务器机制。
版本 {#versions}
上面的生成事实表记录锁定的目录快照和最早观察到的定义。本页没有选定的自然 SQL 运行;固定的 REL_18_6/REL_10_23 源码边界不能当作实测结果,也不能据此推断所有中间版本的行为。
相关 {#related}
08001— sqlclient_unable_to_establish_sqlconnection08007— transaction_resolution_unknown40003— 相关条件
来源 {#sources}
src.fdw-connection-failure.18.6—contrib/postgres_fdw/connection.catREL_18_6commit724edf9bde9d356724ad384a2e196edc3c9f80f7; fixed blob SHA-25667fc002657f2c7df6d93cbf99c933cbc103907d1857ed77aedbb85099ea4dda0(source).src.copy-connection-failure.10.23—src/backend/commands/copy.catREL_10_23commit02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; fixed blob SHA-2560edb032be1ce8d8c90efc28e504aa9e298a2cd26cd374c85da6da0e33ed0915c(source).src.copy-client-eof.18.6—src/backend/commands/copyfromparse.catREL_18_6commit724edf9bde9d356724ad384a2e196edc3c9f80f7; fixed blob SHA-256bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571(source).src.copy-client-eof.10.23—src/backend/commands/copy.catREL_10_23commit02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; fixed blob SHA-2560edb032be1ce8d8c90efc28e504aa9e298a2cd26cd374c85da6da0e33ed0915c(source).src.calls.REL_18_6/src.calls.REL_10_23— fixed local call scans, SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf/00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c; these scans preserve the resolved call context used by the claims.
比较版本
SQLSTATE 证据与已记录的运行版本
cases · source_boundary
{
"assertions": [],
"case_id": "source_boundary",
"cleanup": "Drop the case schema with an owner connection.",
"has_snippet": false,
"position": 0,
"preconditions": [
"A runner-owned disposable target is provisioned only if a source-boundary smoke run is requested."
],
"repair": "Use the concrete source path or component-specific documentation when it applies.",
"trigger": "No artificial SQL trigger is executed; this record preserves the fixed source/definition boundary.",
"versions": [
"10",
"18"
]
}claims · identity.class-and-condition
{
"claim_id": "identity.class-and-condition",
"limits": "Directory identity does not identify every backend or client path.",
"method": "Read the fixed errcodes.txt definition and the locked catalogue metadata.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "08006 is the connection_failure condition in Class 08."
}claims · mechanism.source-boundary
{
"claim_id": "mechanism.source-boundary",
"limits": "This is a bounded source claim; this batch has no selected natural 08006 runtime, and it does not claim that an ordinary client socket failure exposes this SQLSTATE.",
"method": "Trace the fixed REL_18_6 and REL_10_23 source call scans and the recorded source paths.",
"position": 1,
"runtime": [],
"sources": [
"src.fdw-connection-failure.18.6",
"src.copy-connection-failure.10.23",
"src.copy-client-eof.18.6",
"src.copy-client-eof.10.23"
],
"statement": "The fixed source paths resolve 08006 to distinct established-connection failure branches: postgres_fdw cancel warnings, a COPY-to-stdout FATAL in REL_10_23, and COPY client-EOF ERROR paths in REL_18_6 and REL_10_23. The exact diagnostic and severity depend on where the connection loss is detected."
}claims · recovery-boundary
{
"claim_id": "recovery-boundary",
"limits": "This is a source-backed boundary; the COPY EOF branch says nothing about reusing the already-lost client socket, and this batch selected no natural 08006 runtime or ordinary socket failure.",
"method": "Combine the COPY client-EOF source branch, recorded source severities, and the official transaction and savepoint recovery contract.",
"position": 2,
"runtime": [],
"sources": [
"mechanism.source-boundary",
"doc.transactions.18"
],
"statement": "The fixed 08006 variants have different recovery contracts: the COPY client-EOF ERROR detects that the triggering client socket is already at EOF and therefore does not establish a reusable session for sending ROLLBACK; an independently still-connected ERROR can require rollback or savepoint recovery, while FATAL ends the backend; a client EOF without an ErrorResponse may expose no SQLSTATE."
}claims · versions.catalogue-boundary
{
"claim_id": "versions.catalogue-boundary",
"limits": "Presence in a definition file is not an exact behavioral introduction, and the fixed source paths do not prove every intermediate release or socket failure.",
"method": "Read the generated facts block and fixed source records; no runtime result is used for this source-only page.",
"position": 3,
"runtime": [],
"sources": [
"src.errcodes.18.6",
"src.copy-client-eof.18.6",
"src.copy-client-eof.10.23"
],
"statement": "The locked catalogue records 08006 in the listed snapshots; this page compares only the fixed REL_18_6 and REL_10_23 source paths and has no selected natural runtime."
}messages · message.fdw-cancel-send
{
"limits": "The %s value is the dynamic libpq/cancel error text.",
"message_id": "message.fdw-cancel-send",
"path": "",
"position": 0,
"raw": {
"id": "message.fdw-cancel-send",
"limits": "The %s value is the dynamic libpq/cancel error text.",
"primary_template": "could not send cancel request: %s",
"severity_source": "explicit WARNING",
"sources": [
"src.fdw-connection-failure.18.6"
],
"sqlstate": "08006"
},
"severity": "explicit WARNING",
"sources": [
"src.fdw-connection-failure.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "could not send cancel request:",
"position": 0,
"role": "",
"template": "could not send cancel request: %s"
}
]
}messages · message.fdw-cancel-result
{
"limits": "The %s value is the dynamic error text returned while reading the cancel result; the fixed source has more than one call site.",
"message_id": "message.fdw-cancel-result",
"path": "",
"position": 1,
"raw": {
"id": "message.fdw-cancel-result",
"limits": "The %s value is the dynamic error text returned while reading the cancel result; the fixed source has more than one call site.",
"primary_template": "could not get result of cancel request: %s",
"severity_source": "explicit WARNING",
"sources": [
"src.fdw-connection-failure.18.6"
],
"sqlstate": "08006"
},
"severity": "explicit WARNING",
"sources": [
"src.fdw-connection-failure.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "could not get result of cancel request:",
"position": 0,
"role": "",
"template": "could not get result of cancel request: %s"
}
]
}messages · message.copy-connection-lost
{
"limits": "This exact fixed branch is recorded from REL_10_23; the page does not generalize it to every COPY direction or release.",
"message_id": "message.copy-connection-lost",
"path": "",
"position": 2,
"raw": {
"id": "message.copy-connection-lost",
"limits": "This exact fixed branch is recorded from REL_10_23; the page does not generalize it to every COPY direction or release.",
"primary_template": "connection lost during COPY to stdout",
"severity_source": "explicit FATAL",
"sources": [
"src.copy-connection-failure.10.23"
],
"sqlstate": "08006"
},
"severity": "explicit FATAL",
"sources": [
"src.copy-connection-failure.10.23"
],
"templates": [
{
"kind": "primary",
"literal": "connection lost during COPY to stdout",
"position": 0,
"role": "",
"template": "connection lost during COPY to stdout"
}
]
}messages · message.copy-client-eof-open-tx
{
"limits": "The fixed COPY client-EOF path reports this when an open transaction is present; the source confirms the branch, not a selected natural run in this batch.",
"message_id": "message.copy-client-eof-open-tx",
"path": "",
"position": 3,
"raw": {
"id": "message.copy-client-eof-open-tx",
"limits": "The fixed COPY client-EOF path reports this when an open transaction is present; the source confirms the branch, not a selected natural run in this batch.",
"primary_template": "unexpected EOF on client connection with an open transaction",
"severity_source": "explicit ERROR",
"sources": [
"src.copy-client-eof.18.6",
"src.copy-client-eof.10.23"
],
"sqlstate": "08006"
},
"severity": "explicit ERROR",
"sources": [
"src.copy-client-eof.18.6",
"src.copy-client-eof.10.23"
],
"templates": [
{
"kind": "primary",
"literal": "unexpected EOF on client connection with an open transaction",
"position": 0,
"role": "",
"template": "unexpected EOF on client connection with an open transaction"
}
]
}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": "REL_18_6",
"url": ""
}sources · src.calls.REL_10_23
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "raw/calls/REL_10_23.jsonl",
"position": 2,
"sha256": "00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c",
"source_id": "src.calls.REL_10_23",
"tag": "REL_10_23",
"url": ""
}sources · src.fdw-connection-failure.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "contrib/postgres_fdw/connection.c",
"position": 3,
"sha256": "67fc002657f2c7df6d93cbf99c933cbc103907d1857ed77aedbb85099ea4dda0",
"source_id": "src.fdw-connection-failure.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/contrib/postgres_fdw/connection.c#L1462-L1464"
}sources · src.copy-connection-failure.10.23
{
"commit": "02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/commands/copy.c",
"position": 4,
"sha256": "0edb032be1ce8d8c90efc28e504aa9e298a2cd26cd374c85da6da0e33ed0915c",
"source_id": "src.copy-connection-failure.10.23",
"tag": "REL_10_23",
"url": "https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/commands/copy.c#L525-L527"
}sources · manifest.08006
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "verify/cases/08006/cases.json",
"position": 5,
"sha256": "205dd83742e554dc0ceb466ed9acd023f538785306e2a2b29a7ec3842a8f50af",
"source_id": "manifest.08006",
"tag": "workspace",
"url": "verify/cases/08006/cases.json"
}sources · src.copy-client-eof.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/commands/copyfromparse.c",
"position": 6,
"sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
"source_id": "src.copy-client-eof.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L276-L303"
}sources · src.copy-client-eof.10.23
{
"commit": "02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/commands/copy.c",
"position": 7,
"sha256": "0edb032be1ce8d8c90efc28e504aa9e298a2cd26cd374c85da6da0e33ed0915c",
"source_id": "src.copy-client-eof.10.23",
"tag": "REL_10_23",
"url": "https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/commands/copy.c#L587-L614"
}sources · doc.transactions.18
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "doc/src/sgml/xact.sgml",
"position": 8,
"sha256": "b48fbe8bd02ce3d1181a350c88c8baa6e11c73edc90a936e77b180daef328c5c",
"source_id": "doc.transactions.18",
"tag": "PG18-docs",
"url": "https://www.postgresql.org/docs/18/tutorial-transactions.html"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:27579a490920a8273428e87cff8d866374221184a614a8ca900493f2805c08e1
正文语言: zh-Hans · english-manuals:27579a490920a8273428e87cff8d866374221184a614a8ca900493f2805c08e1