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

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

Wiki / SQLSTATE

57P05 — idle_session_timeout

空闲会话超过 idle_session_timeout 被终止。

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

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

aliases
未知
class name
Operator Intervention
condition name
idle_session_timeout
lang
en
sqlstate
57P05

版本定义 PG 18

57P05

速览 {#at-a-glance}

57P05 在 idle_session_timeout 到期、backend 确实处于命令之间的 idle 状态时终止 session。固定代码只在无事务分支启动这个 timer;idle-in-transaction 使用另一条件和 timer。

含义 {#meaning}

固定 primary 是 terminating connection due to idle-session timeout,severity 为 FATAL。PostgresMain 在 backend 报告 STATE_IDLE 后、且 IsTransactionOrTransactionBlock() 为假时才启用 idle-session timer。读到命令后立即关闭该 timer。因此 57P05 是 session 生命周期终止,区别于 statement timeout 57014、lock timeout 55P03、idle-in-transaction timeout 25P03 和 transaction timeout 25P04。

消息 {#messages}

  • primary:terminating connection due to idle-session timeout。
  • severity:FATAL;timer interrupt 会终止连接,不返回可恢复的语句级 ERROR。
  • 边界:命令之间真正 idle 的 session 使用 57P05;开放事务内 idle 的 session 使用单独的 idle-in-transaction timer/条件。

诊断 {#diagnosis}

记录 primary、backend PID、idle_session_timeout 值及来源、最后一条命令、pg_stat_activity 状态、事务状态和服务器日志。确认 timer 启动时 session 是 idle 还是 idle in transaction。单凭客户端耗时不能把它和 statement/lock timeout 区分开,还应结合连接最后的 ReadyForQuery 状态解释 SQLSTATE。

处理 {#response}

关闭或重建已过期连接,把长时间工作改成明确的工作单元,不要依赖闲置 session。只有策略允许且工作负载确有需要时才调整 idle_session_timeout。FATAL 会关闭连接,原 session 上没有可发送的有效 ROLLBACK;重连后,重放非幂等命令前先核对持久化效果。若工作实际是在事务内 idle,应分别诊断 25P03/25P04 和事务归属。

版本 {#versions}

锁定目录从 14.0 记录此条件;该目录边界不等于精确实现引入版本。固定源码覆盖 PostgreSQL 18.6。

相关 {#related}

57P01、25P03、25P04、57014、55P03

来源 {#sources}

src/backend/tcop/postgres.c#L3504-3513

src/backend/tcop/postgres.c#L4585-4650

src/backend/tcop/postgres.c#L4704-4721

结构化证据记录保存消息和 idle 状态边界。

比较版本

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

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "57P05 is idle_session_timeout in SQLSTATE Class 57."
}
claims · resolved-paths
{
  "claim_id": "resolved-paths",
  "limits": "Source confirmation is not natural runtime.",
  "method": "Read complete fixed source contexts.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.0",
    "src.path.1",
    "src.path.2"
  ],
  "statement": "The cited PostgreSQL 18.6 source paths support the concrete phase, message, and lifecycle boundary described."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 57P05 from 14.0; that boundary does not prove exact implementation introduction."
}
claims · idle-boundary
{
  "claim_id": "idle-boundary",
  "limits": "",
  "method": "Read the complete PostgresMain state branches and timeout disable path.",
  "position": 3,
  "runtime": [],
  "sources": [
    "src.path.1",
    "src.path.2"
  ],
  "statement": "The idle-session timer starts only in the no-transaction STATE_IDLE branch and is disabled when input arrives; idle-in-transaction uses a separate timer and condition."
}
messages · message.0
{
  "limits": "",
  "message_id": "message.0",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.0",
    "primary_template": "terminating connection due to idle-session timeout",
    "severity_source": "FATAL",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "57P05"
  },
  "severity": "FATAL",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "terminating connection due to idle-session timeout",
      "position": 0,
      "role": "",
      "template": "terminating connection due to idle-session timeout"
    }
  ]
}
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#L439"
}
sources · src.path.0
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/tcop/postgres.c",
  "position": 1,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.path.0",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L3511"
}
sources · src.path.1
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/tcop/postgres.c",
  "position": 2,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.path.1",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L4585"
}
sources · src.path.2
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/tcop/postgres.c",
  "position": 3,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.path.2",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L4704"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:bce22c115e78cb6aec27ac17a9c48e1070dea6703f591fe0f767b59ec9ec9ebb

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