↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

57P05 — idle_session_timeout

57P05 terminates a session after idlesessiontimeout expires while the backend is truly idle between commands. The fixed code starts this timer only in the no-transaction branch; idle-in-transaction has a separate condition and timer.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

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

Definition PG 18

57P05

At a glance {#at-a-glance}

57P05 terminates a session after idle_session_timeout expires while the backend is truly idle between commands. The fixed code starts this timer only in the no-transaction branch; idle-in-transaction has a separate condition and timer.

Meaning {#meaning}

The fixed primary is terminating connection due to idle-session timeout at FATAL. In PostgresMain, the idle-session timer is enabled after the backend reports STATE_IDLE and only in the branch where IsTransactionOrTransactionBlock() is false. The timer is disabled as soon as a command is read. This makes 57P05 a session-lifecycle termination, distinct from statement timeout 57014, lock timeout 55P03, idle-in-transaction timeout 25P03, and transaction timeout 25P04.

Messages {#messages}

  • Primary: terminating connection due to idle-session timeout.
  • Severity: FATAL; the timer interrupt terminates the connection rather than returning a recoverable statement ERROR.
  • Boundary: a truly idle session between commands uses 57P05; a session idle inside an open transaction uses the separate idle-in-transaction timer/condition.

Diagnosis {#diagnosis}

Capture the primary, backend PID, idle_session_timeout value and source, last command, pg_stat_activity state, transaction status, and server log. Verify whether the session was idle or idle in transaction when the timer started. Elapsed client request time alone cannot distinguish this from statement or lock timeout, and the SQLSTATE should be interpreted with the connection's last ReadyForQuery state.

Response {#response}

Close or recreate the expired connection and make long-lived work explicit rather than holding an unused session. Adjust idle_session_timeout only when policy permits and the workload needs it. Because FATAL closes the connection, there is no useful ROLLBACK command to send on that session; after reconnecting, verify durable effects before replaying a non-idempotent command. If the workload was idle in a transaction, diagnose 25P03/25P04 and transaction ownership separately.

Versions {#versions}

The locked catalogue records this condition from 14.0; that boundary does not prove the exact implementation-introduction version. Fixed source coverage is PostgreSQL 18.6.

Related {#related}

57P01, 25P03, 25P04, 57014, 55P03

Sources {#sources}

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

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

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

The structured evidence record records the message and idle-state boundary.

Compare versions

SQLSTATE evidence and recorded runtime versions

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"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:bce22c115e78cb6aec27ac17a9c48e1070dea6703f591fe0f767b59ec9ec9ebb

Text language: en · english-manuals:bce22c115e78cb6aec27ac17a9c48e1070dea6703f591fe0f767b59ec9ec9ebb