Skip to content

fix(pg): set idle_session_timeout=0 for pg connections#4589

Merged
dtunikov merged 2 commits into
mainfrom
fix/idle-session-timeout
Jul 16, 2026
Merged

fix(pg): set idle_session_timeout=0 for pg connections#4589
dtunikov merged 2 commits into
mainfrom
fix/idle-session-timeout

Conversation

@dtunikov

@dtunikov dtunikov commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

we've received a few alerts that were caused by session timeout (can be set to non zero on source db).
example error:
Logical message processing error: failed to get customTypeMapping: FATAL: terminating connection due to idle-session timeout (SQLSTATE 57P05)

@dtunikov
dtunikov requested a review from a team as a code owner July 15, 2026 15:47
@dtunikov
dtunikov requested a review from Copilot July 15, 2026 16:17
@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

test2

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

test review feasibility

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent Postgres connections used by the Flow Postgres connector (including replication connections) from being terminated by a non-zero idle_session_timeout configured on the source database, which has been causing CDC/logical message processing failures.

Changes:

  • Set idle_session_timeout=0 on standard Postgres connector connections via RuntimeParams.
  • Set idle_session_timeout=0 on replication connections via RuntimeParams.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
flow/connectors/postgres/postgres.go Adds idle_session_timeout=0 to the startup/runtime parameters for standard Postgres connections.
flow/connectors/postgres/postgres_source.go Adds idle_session_timeout=0 to the startup/runtime parameters for replication connections.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 88 to 92
connConfig.Config.RuntimeParams["timezone"] = "UTC"
connConfig.Config.RuntimeParams["idle_in_transaction_session_timeout"] = "0"
connConfig.Config.RuntimeParams["idle_session_timeout"] = "0"
connConfig.Config.RuntimeParams["statement_timeout"] = "0"
connConfig.Config.RuntimeParams["DateStyle"] = "ISO, DMY"
Comment on lines 85 to 89
replConfig.Config.RuntimeParams["timezone"] = "UTC"
replConfig.Config.RuntimeParams["idle_in_transaction_session_timeout"] = "0"
replConfig.Config.RuntimeParams["idle_session_timeout"] = "0"
replConfig.Config.RuntimeParams["statement_timeout"] = "0"
replConfig.Config.RuntimeParams["replication"] = "database"
@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

Code review

1 issue found. Checked for bugs and CLAUDE.md compliance.

On flow/connectors/postgres/postgres.go line 90:

Bug: idle_session_timeout was introduced in PostgreSQL 14, but PeerDB supports PostgreSQL 12+. Setting it in RuntimeParams sends it in the startup message before the connection is established, so the server version is unknown at this point. PostgreSQL 12 and 13 will reject the connection with a FATAL error (unrecognized configuration parameter idle_session_timeout).

This differs from idle_in_transaction_session_timeout (line above), which was introduced in PostgreSQL 9.6 and is safe for all supported versions.

The same issue applies to the identical change in flow/connectors/postgres/postgres_source.go line 87.

Suggested fix: Instead of setting this in RuntimeParams, issue SET idle_session_timeout = 0 after the connection is established, gated on pgVersion >= shared.POSTGRES_14. The codebase already uses this version-gating pattern extensively (e.g., postgres_source.go:246).

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

test

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

Code review

1 issue found. Checked for bugs and CLAUDE.md compliance.

On flow/connectors/postgres/postgres.go line 90:

Bug: idle_session_timeout was introduced in PostgreSQL 14, but PeerDB supports PostgreSQL 12+ (enforced in flow/connectors/postgres/validate.go).

Setting it in RuntimeParams sends it in the startup message before the connection is established, so the server version is unknown at this point. PostgreSQL 12 and 13 will reject the connection with a FATAL error (unrecognized configuration parameter "idle_session_timeout").

This differs from idle_in_transaction_session_timeout (line above), which was introduced in PostgreSQL 9.6 and is safe for all supported versions.

The same issue applies to the identical change in flow/connectors/postgres/postgres_source.go.

Suggested fix: Instead of setting this in RuntimeParams, issue SET idle_session_timeout = 0 after the connection is established, gated on pgVersion >= shared.POSTGRES_14. The codebase already uses this version-gating pattern extensively (e.g., postgres_source.go:246).

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

test-cleanup-check

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

Comment cleanup - please ignore

@dtunikov
dtunikov merged commit 1f84ed1 into main Jul 16, 2026
20 checks passed
@dtunikov
dtunikov deleted the fix/idle-session-timeout branch July 16, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants