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(postgres): stop a duckgres pooler cooldown from flooding error tracking (#101667)

Tom Owersd69c917b13df
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 44934f9f5a2f..16cb2e0a0cba 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
@@ -1279,6 +1279,22 @@ def _is_statement_timeout_error(error: BaseException) -> bool:
)
+def _is_pooler_login_cooldown_error(error: BaseException) -> bool:
+ """True when a connection pooler (PgBouncer and similar) is in its `server_login_retry`
+ cooldown after a backend login attempt failed.
+
+ The cooldown clears on its own once the pooler's next scheduled retry succeeds, so it's the
+ same "expected, not a bug" shape the other exclusions here degrade quietly for. Matched on
+ message rather than exception type: a Postgres-wire-compatible engine backed by DuckDB's
+ `postgres_query()` table function (e.g. DuckLake's duckgres bridge) can wrap the underlying
+ connection failure in an unrelated exception class (observed as
+ `SyntaxErrorOrAccessRuleViolation`), so the type-based checks above (`_is_connection_dropped_error`
+ et al.) don't catch it here.
+ """
+ message = str(error).lower()
+ return "server login has been failing" in message and "server_login_retry" in message
+
+
def _rls_active_from_conn(
connection: psycopg.Connection,
schema: str | None,
@@ -1359,8 +1375,10 @@ def _rls_active_from_conn(
# outcome: this lookup is best-effort like the PK/xmin/index lookups it runs alongside, and
# they all run under the same 30s SET LOCAL guard against a runaway catalog scan — hitting
# it is the guard working, not new information about a bug here (mirrors
- # `_xmin_capable_tables_from_conn`, which already degrades quietly for it). Still capture
- # genuinely unexpected failures.
+ # `_xmin_capable_tables_from_conn`, which already degrades quietly for it). A pooler
+ # login-retry cooldown (e.g. a duckgres-backed source's own metadata store momentarily
+ # can't log in) is the same self-healing shape — see `_is_pooler_login_cooldown_error`.
+ # Still capture genuinely unexpected failures.
if (
not connection.closed
and not connection.broken
@@ -1368,6 +1386,7 @@ def _rls_active_from_conn(
and not _is_unsupported_function_error(e, "row_security_active")
and not _is_unsupported_statement_timeout_error(e)
and not _is_statement_timeout_error(e)
+ and not _is_pooler_login_cooldown_error(e)
):
capture_exception(e)
return {}
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 863f83c19cf0..7c82b6f04967 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
@@ -9028,6 +9028,26 @@ class TestRlsActiveFromConnErrorHandling:
assert result == {}
capture_mock.assert_called_once()
+ def test_pooler_login_cooldown_error_is_not_captured(self):
+ # A Postgres-wire-compatible source backed by DuckDB's `postgres_query()` (e.g. DuckLake's
+ # duckgres bridge) can surface a transient PgBouncer server_login_retry cooldown wrapped in
+ # an unrelated exception class (observed as SyntaxErrorOrAccessRuleViolation), so this must
+ # be caught by message rather than type. It self-heals: degrade quietly like the other
+ # expected shapes here instead of flooding error tracking.
+ conn = self._conn_raising(
+ psycopg.errors.SyntaxErrorOrAccessRuleViolation(
+ 'Unable to connect to Postgres at "host=... dbname=...": connection to server at '
+ '"..." failed: FATAL: server login has been failing, cached error: connect failed '
+ "(server_login_retry)"
+ )
+ )
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.postgres.postgres.capture_exception"
+ ) as capture_mock:
+ result = _rls_active_from_conn(cast(Any, conn), "public", ["t"])
+ assert result == {}
+ capture_mock.assert_not_called()
+
def test_failed_sql_transaction_is_not_captured(self):
# This lookup shares a connection with earlier best-effort metadata queries (PK + index
# discovery). When one of those fails on a non-Postgres engine (e.g. Redshift) its exception