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): treat pgcat AllServersDown pooler failure as transient (#71102)

Tom Owersfc3ccb73ea83
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 09ea852b1a9e..1f7bf752279f 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
@@ -219,6 +219,16 @@ _CONNECTION_DROPPED_ERROR_SUBSTRINGS = (
# ("password authentication failed", "SASL authentication failed"), and exclude the volatile
# millisecond value.
"authentication did not complete within",
+ # pgcat (a Rust Postgres pooler) refuses to hand out a backend when every server in the pool is
+ # currently banned/down — a failed health check bans a server and pgcat auto-unbans it after
+ # `ban_time` — reporting it as SQLSTATE 58000 ("could not get connection from the pool -
+ # AllServersDown"), which psycopg maps to OperationalError. It's transient by construction (a
+ # banned server rejoins once it passes a health check, or the ban expires), the pgcat analog of
+ # Supavisor's ECHECKOUT* pool-checkout failures above, so a fresh reconnect recovers. It can land
+ # on the first discovery query (`SELECT version()` in `_is_duckdb_connection`), so the discovery
+ # retry must catch it. Match the stable prefix + reason and leave pgcat's non-transient reasons
+ # (e.g. BadConfig) to surface.
+ "could not get connection from the pool - allserversdown",
)
# Supavisor (Supabase's connection pooler) doesn't surface a dropped upstream connection with a
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 381e43cf8527..9b4db1914274 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
@@ -1355,6 +1355,11 @@ class TestIsConnectionDroppedError:
psycopg.errors.ConnectionFailure(
"Failed to connect to database: authentication did not complete within 15000ms"
),
+ # pgcat refuses to hand out a backend when every pooled server is banned/down, reporting
+ # it as SQLSTATE 58000 (psycopg's SystemError, an OperationalError) rather than the
+ # Supavisor XX000 InternalError_ codes above. Transient — a banned server rejoins on a
+ # passing health check or once its ban expires — so the reconnect must catch it.
+ psycopg.errors.SystemError("could not get connection from the pool - AllServersDown"),
],
)
def test_connection_dropped_errors_are_detected(self, error):