fix(pg): set idle_session_timeout=0 for pg connections#4589
Conversation
|
test2 |
|
test review feasibility |
There was a problem hiding this comment.
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=0on standard Postgres connector connections viaRuntimeParams. - Set
idle_session_timeout=0on replication connections viaRuntimeParams.
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.
| 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" |
| 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" |
Code review1 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). |
|
test |
Code review1 issue found. Checked for bugs and CLAUDE.md compliance. On Bug: Setting it in This differs from The same issue applies to the identical change in Suggested fix: Instead of setting this in |
|
test-cleanup-check |
|
Comment cleanup - please ignore |
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)