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 read-only cluster errors as non-retryable (#69590)

Tom Owers19dd8d821d30
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 de7d4d1c6e37..76b3b36302cc 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
@@ -471,6 +471,18 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
"connect until the database is available again. Upgrade your provider's plan or wait "
"for the quota to reset, then re-enable the sync."
),
+ # The provider has put the cluster into read-only mode, so it rejects our read (the
+ # server-side cursor runs its SELECT inside a read/write transaction). PlanetScale's
+ # pg_readonly reports "invalid statement because cluster is read-only"; the cluster only
+ # leaves this state once the customer restores write access (free up storage, upgrade the
+ # plan), so a whole-activity retry re-reads into the same wall. Match the stable phrase and
+ # exclude the volatile leading "pg_readonly:" prefix and trailing docs URL.
+ "cluster is read-only": (
+ "Your database provider has put the database cluster into read-only mode, so it's "
+ 'rejecting PostHog\'s queries ("cluster is read-only"). Providers such as PlanetScale '
+ "do this when a storage or usage limit is exceeded. Restore write access to the cluster "
+ "(for example free up storage or upgrade your plan), then re-enable the sync."
+ ),
# A physical standby / read replica started with `hot_standby = off` refuses every
# connection while in recovery, raising SQLSTATE 57P03 "FATAL: the database system is not
# accepting connections / DETAIL: Hot standby mode is disabled". It will never serve read
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 13c4ffe36112..6f54c7d7f245 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
@@ -500,6 +500,28 @@ class TestPostgresSourceNonRetryableErrors:
assert friendly, "Exceeded compute-time quota error should surface an actionable message"
assert "compute-time quota" in friendly[0]
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Raw psycopg message (what the activity-level check sees via str(e)). The leading
+ # "pg_readonly:" prefix and trailing docs URL are volatile; "cluster is read-only" is stable.
+ "pg_readonly: invalid statement because cluster is read-only. See planetscale.com/docs/postgres/troubleshooting/readonly",
+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.
+ "InternalError_: pg_readonly: invalid statement because cluster is read-only. See planetscale.com/docs/postgres/troubleshooting/readonly",
+ ],
+ )
+ def test_read_only_cluster_is_non_retryable(self, source, error_msg):
+ non_retryable = source.get_non_retryable_errors()
+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
+ assert is_non_retryable, f"Read-only cluster error should be non-retryable: {error_msg}"
+
+ def test_read_only_cluster_returns_friendly_message(self, source):
+ non_retryable = source.get_non_retryable_errors()
+ error_msg = "pg_readonly: invalid statement because cluster is read-only. See planetscale.com/docs/postgres/troubleshooting/readonly"
+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]
+ assert friendly, "Read-only cluster error should surface an actionable message"
+ assert "read-only mode" in friendly[0]
+
@pytest.mark.parametrize(
"error_msg",
[