Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): recognize Neon's pooler rejection of libpq options (#77899)

Tom Owers412b8a7a4c16
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.py
index 155a6e135afd..806317cc9db9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/stream_reader.py
@@ -134,7 +134,10 @@ class PgCDCStreamReader:
# sits idle between yields as the caller flushes to S3 and advances the slot —
# statement_timeout doesn't apply there because no statement is running. Both are
# dropped if the source sits behind a pooler that rejects the libpq `options`
- # parameter (CDC sources never do).
+ # parameter — CDC sources do sit behind one (a Neon pooled endpoint serves the peek
+ # functions fine), and without the fallback the connection can never be opened at
+ # all. The activity's start-to-close and heartbeat timeouts still bound a stalled
+ # peek when the server-side ceiling is gone.
options="-c statement_timeout=1800000 -c idle_in_transaction_session_timeout=0",
),
logger,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py
index 349e133bc534..48918180f928 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py
@@ -672,12 +672,15 @@ def _get_sslmode(require_ssl: bool) -> str:
# Transaction-mode connection poolers reject the libpq `options` startup parameter outright:
# Supabase's Supavisor (port 6543) and PgBouncer in transaction mode report "unsupported startup
# parameter: options", and AWS RDS Proxy reports "RDS Proxy currently doesn't support command-line
-# options". We only send `options` to pin client_encoding=UTF8 for Redshift's legacy UNICODE alias
-# (see FORCE_UTF8_CLIENT_ENCODING), and Redshift never sits behind these poolers — so when a server
-# rejects `options`, dropping it and retrying is safe (UTF8 is the default client encoding for real
-# Postgres). The RDS Proxy text uses a typographic apostrophe, so match the apostrophe-free tail.
+# options". Neon's pooler names the offending setting instead — "unsupported startup parameter in
+# options: statement_timeout" — so match on the prefix rather than any one parameter name.
+# Beyond client_encoding=UTF8 for Redshift's legacy UNICODE alias (see FORCE_UTF8_CLIENT_ENCODING),
+# `options` only ever carries server-side timeouts that the caller's own deadlines already bound —
+# so when a server rejects it, dropping it and retrying is safe. The RDS Proxy text uses a
+# typographic apostrophe, so match the apostrophe-free tail.
_OPTIONS_STARTUP_PARAM_UNSUPPORTED_SUBSTRINGS = (
"unsupported startup parameter: options",
+ "unsupported startup parameter in options",
"support command-line options",
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
index b23e7ff5fc3b..17f46c4c45a5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py
@@ -2100,9 +2100,10 @@ class TestConnectToPostgresMultiAddressFailover:
assert connect_mock.call_args.kwargs["hostaddr"] == "203.0.113.5"
-# Transaction-mode poolers (Supabase Supavisor on :6543, PgBouncer transaction mode, AWS RDS Proxy)
-# reject the libpq `options` startup parameter we send to pin client_encoding=UTF8. When they do, we
-# drop `options` and retry rather than failing the connection.
+# Transaction-mode poolers (Supabase Supavisor on :6543, PgBouncer transaction mode, AWS RDS Proxy,
+# Neon's pooled endpoint) reject the libpq `options` startup parameter we send to pin
+# client_encoding=UTF8 and, on the CDC path, server-side timeouts. When they do, we drop `options`
+# and retry rather than failing the connection.
class TestConnectOptionsStartupParamFallback:
@pytest.mark.parametrize(
"message,expected",
@@ -2116,6 +2117,19 @@ class TestConnectOptionsStartupParamFallback:
"doesn’t support command-line options.",
True,
),
+ # Neon names the rejected setting after the colon, so a match on the exact
+ # "parameter: options" wording above misses it and the connection never opens.
+ (
+ 'connection to server at "1.2.3.4", port 5432 failed: ERROR: unsupported startup '
+ "parameter in options: statement_timeout. Please use unpooled connection or remove "
+ "this parameter from the startup package.",
+ True,
+ ),
+ (
+ 'connection to server at "1.2.3.4", port 5432 failed: ERROR: unsupported startup '
+ "parameter in options: idle_in_transaction_session_timeout.",
+ True,
+ ),
("password authentication failed for user", False),
("server closed the connection unexpectedly", False),
],