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 retrying a connection to a hibernated branch (#111512)

Tom Owersa8861f6202ec
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
index 8dd5ad478233..4f898afd3c17 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py
@@ -518,6 +518,16 @@ class PostgresSource(
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
+ # A serverless provider (observed on Xata) refuses the connection while the branch is
+ # hibernated. A hibernated branch does not wake on connect: the refusal itself asks for a
+ # reactivation, which only the customer can do, so every retry re-hits the same refusal.
+ # Match the stable phrase because libpq prefixes it with the customer's host and port.
+ # This entry comes first because the finalizer takes the first match, and a multi-address
+ # refusal can also carry a generic "Connection refused" or timeout for another address.
+ "branch is hibernated": (
+ "Your database provider hibernated this branch, so PostHog can't connect. "
+ "Reactivate the branch in your provider's dashboard, then re-enable the sync."
+ ),
# xmin can't run against this relation (server < PG13, no primary key, or a partitioned
# parent) — deterministic, so don't retry. `XminUnsupportedError` matches once Temporal
# wraps the failure; the message fragment matches the raw activity-level `str(e)`.
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 770635a4f3de..42845bf07d3c 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
@@ -485,6 +485,9 @@ class TestPostgresSourceNonRetryableErrors:
# Distinct from the transient "not yet accepting connections" startup refusal above (which
# reads "not yet", not "not currently"). Host/db are invented, not a real value.
'connection failed: connection to server at "db.example.com", port 5432 failed: FATAL: database "postgres" is not currently accepting connections',
+ # A serverless provider refuses every connect while the branch is hibernated, until the
+ # customer reactivates it. Host and IP are invented, not real values.
+ 'connection failed: connection to server at "203.0.113.7", port 5432 failed: FATAL: branch is hibernated, reactivate it to continue',
],
)
def test_permanent_connection_errors_are_non_retryable(self, source, error_msg):
@@ -524,6 +527,22 @@ class TestPostgresSourceNonRetryableErrors:
assert matches[0] is not None, "a dropped relation must surface an actionable message, not raw driver text"
assert "no longer exists" in matches[0].lower()
+ def test_hibernated_branch_wins_over_a_generic_refusal_for_another_address(self, source):
+ # Host and IPs are invented, not real values.
+ error_msg = (
+ 'connection failed: connection to server at "203.0.113.7", port 5432 failed: Connection refused '
+ 'Multiple connection attempts failed. All failures were: - host: "db.example.com", port: "5432", '
+ 'hostaddr: "203.0.113.8": connection failed: connection to server at "203.0.113.8", port 5432 '
+ "failed: FATAL: branch is hibernated, reactivate it to continue"
+ )
+ matches = [
+ friendly
+ for pattern, friendly in source.get_non_retryable_errors().items()
+ if error_message_matches(error_msg, [pattern])
+ ]
+ assert matches and matches[0] is not None
+ assert "reactivate the branch" in matches[0].lower()
+
def test_connect_timeout_surfaces_actionable_message(self, source):
# A persistently timing-out connect stays non-retryable, but must surface firewall/reachability
# guidance rather than the bare "connection timeout expired" driver text. Mirror the finalizer's