: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(postgres): treat server out-of-memory as non-retryable (#65247)
Tom Owerseb9946883991
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex a8b45232846b..2b7c5871b459 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -405,6 +405,23 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa),"DiskFull": "Source database ran out of disk space. Free up disk space on your database server or add an index on your incremental field to reduce temp file usage.","No space left on device": "Source database ran out of disk space. Free up disk space on your database server or add an index on your incremental field to reduce temp file usage.",+ # The source server itself ran out of memory (PostgreSQL SQLSTATE 53200, psycopg's+ # `OutOfMemory`) — "out of memory ... Failed on request of size N in memory context ...".+ # We've seen it fire even on the tiny schema-discovery queries in `_get_table` (a few KB+ # in server-side contexts like "MessageContext" / "get_actual_variable_range workspace"),+ # which means the server is memory-starved regardless of our workload — an undersized+ # instance, work_mem set too high, or too many concurrent connections. Retrying re-reads+ # into the same wall, so it's non-retryable like the disk-full siblings above (same class+ # 53 "insufficient resources"). The lowercase message matches both the raw activity-level+ # str(e) and the Temporal-wrapped "OutOfMemory: ..." workflow-level form. The volatile+ # request size and memory-context name are excluded from the match.+ "out of memory": (+ "Your database server ran out of memory while PostHog was reading from it "+ '(PostgreSQL reported "out of memory"). This usually means the server is undersized, '+ "work_mem is set too high, or too many connections are competing for memory. Reduce "+ "memory pressure on your database (for example lower work_mem, reduce concurrent "+ "connections, or increase the instance's memory), then re-enable the sync."+ ),# Raised when a Postgres numeric value cannot be represented in any Delta-compatible# decimal type — the pipeline falls back through the best-fit decimal and# `decimal256(76, 32)` before giving up. Only triggers when source data genuinelydiff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex c4e75cc9fd3d..c14234e04ddc 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -402,6 +402,29 @@ 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 request size+ # and memory-context name are volatile; the "out of memory" text is stable.+ 'out of memory DETAIL: Failed on request of size 12 in memory context "MessageContext".',+ 'out of memory DETAIL: Failed on request of size 32816 in memory context "get_actual_variable_range workspace".',+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ 'OutOfMemory: out of memory DETAIL: Failed on request of size 32816 in memory context "MessageContext".',+ ],+ )+ def test_server_out_of_memory_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"Server out-of-memory error should be non-retryable: {error_msg}"++ def test_server_out_of_memory_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = 'out of memory DETAIL: Failed on request of size 12 in memory context "MessageContext".'+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Server out-of-memory error should surface an actionable message"+ assert "ran out of memory" in friendly[0]+@pytest.mark.parametrize("error_msg",[