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 database that isn't accepting connections (#94596)

Tom Owersbe9d6bda02b0
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 e83e41b2dc83..7a7d0be2cacd 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
@@ -773,6 +773,19 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
"Enable hot_standby on the replica and restart it, or point this source at the primary "
"database, then re-enable the sync."
),
+ # SQLSTATE 57P03 with the message "database <name> is not currently accepting connections":
+ # the server is up (it answered with a FATAL) but the target database has datallowconn
+ # turned off, or a managed provider has paused/suspended it (e.g. an inactive Supabase
+ # project). Deterministic until the customer restores it, so a whole-activity retry re-hits
+ # the same refusal — distinct from the transient "the database system is not yet accepting
+ # connections" startup refusal kept retryable in postgres.py (which reads "not yet", not "not
+ # currently"). Match the stable phrase and exclude the volatile database name.
+ "is not currently accepting connections": (
+ "The database you selected to sync isn't accepting new connections right now — this "
+ "usually means it's paused or set to disallow connections (managed providers such as "
+ "Supabase pause inactive projects). Resume or reactivate the database, then re-enable "
+ "the sync."
+ ),
# A single recovery conflict ("conflict with recovery") is transient and retried in-process,
# so it stays retryable. This abort is only raised once those retries are exhausted — by then
# the condition is sustained and a whole-activity retry just re-reads from offset 0 into the
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 5b06a90a6d07..763d2d758f4f 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
@@ -444,6 +444,11 @@ class TestPostgresSourceNonRetryableErrors:
# hit a plan limit. Account-level state only the customer can lift, so retrying re-hits
# the same refusal — must not keep retrying. Host/port are invented, not a real value.
'connection failed: connection to server at "db.example.com", port 5432 failed: Your account has restrictions: planLimitReached. Please contact your provider to resolve account restrictions.',
+ # The target database has datallowconn off, or a managed provider paused/suspended it
+ # (SQLSTATE 57P03). Permanent until the customer restores it, so it must not keep retrying.
+ # 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',
],
)
def test_permanent_connection_errors_are_non_retryable(self, source, error_msg):
@@ -498,6 +503,22 @@ class TestPostgresSourceNonRetryableErrors:
assert matches[0] is not None, "connect timeout must surface an actionable message, not raw driver text"
assert "firewall" in matches[0].lower()
+ def test_database_not_accepting_connections_surfaces_actionable_message(self, source):
+ # A paused/disallowed database must stop retrying and tell the customer to restore it,
+ # rather than storing the raw driver text (which echoes the host, IP, and database name).
+ # Mirror the finalizer's first-match selection so a future reorder that shadows it with an
+ # earlier None-valued key is caught. Host/db are invented, not a real value.
+ error_msg = 'connection failed: connection to server at "db.example.com", port 5432 failed: FATAL: database "postgres" is not currently accepting connections'
+ matches = [
+ friendly
+ for pattern, friendly in source.get_non_retryable_errors().items()
+ if error_message_matches(error_msg, [pattern])
+ ]
+ assert matches, "a database not accepting connections must be classified non-retryable"
+ assert matches[0] is not None, "a database not accepting connections must surface an actionable message"
+ assert "re-enable the sync" in matches[0].lower()
+ assert "db.example.com" not in matches[0]
+
def test_plan_limit_restriction_surfaces_actionable_message(self, source):
# A proxy plan-limit refusal must stop retrying and explain how to lift the restriction,
# rather than storing the raw provider text. Mirror the finalizer's first-match selection.