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 hot-standby-disabled replica as non-retryable (#67190)

Tom Owerscecb7070a8db
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 1c4b82a44988..86facc699ae8 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
@@ -442,6 +442,20 @@ 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."
),
+ # 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
+ # queries until hot_standby is enabled (a config change + restart) or the replica is
+ # promoted to primary, so a whole-activity retry re-hits the same wall every time. Match
+ # the stable DETAIL, NOT the broad "the database system is not accepting connections" — that
+ # message also fires transiently while a server is starting up, shutting down, or failing
+ # over and must stay retryable (see the "the database system is starting up" mapping above).
+ "Hot standby mode is disabled": (
+ "PostHog connected to a PostgreSQL standby (read replica) that isn't accepting "
+ 'connections because hot standby is turned off ("Hot standby mode is disabled"). '
+ "Enable hot_standby on the replica and restart it, or point this source at the primary "
+ "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 ead589d2d902..acd0885aa429 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
@@ -305,6 +305,10 @@ class TestPostgresSourceNonRetryableErrors:
# Mid-stream SSL/connection drops during schema discovery — the pooler culled an idle
# connection or the socket died. A fresh attempt reconnects, so these must stay retryable.
"consuming input failed: SSL connection has been closed unexpectedly",
+ # The socket-level variant of the same TLS drop (network blip / idle cull mid-stream). It
+ # triggers the offset-chunking recovery and must stay retryable — only the reconnect wall it
+ # can hit on a hot-standby-disabled replica is non-retryable (see the permanent cases below).
+ "consuming input failed: SSL SYSCALL error: EOF detected",
"the connection is lost",
],
)
@@ -334,6 +338,10 @@ class TestPostgresSourceNonRetryableErrors:
# Manager), not PostgreSQL's "password authentication failed for user". Newlines are
# normalized to spaces upstream, so the real message arrives as the doubled single line.
'connection failed: connection to server at "127.0.0.1", port 35425 failed: FATAL: The password that was provided for the role postgres is wrong. connection to server at "127.0.0.1", port 35425 failed: FATAL: This RDS Proxy requires TLS connections',
+ # A read replica started with `hot_standby = off` refuses every connection (SQLSTATE 57P03).
+ # Newlines are normalized to spaces upstream, so the FATAL/DETAIL pair arrives on one line.
+ # Permanent until the replica's config changes or it's promoted — must not keep retrying.
+ 'connection failed: connection to server at "10.0.0.1", port 5432 failed: FATAL: the database system is not accepting connections DETAIL: Hot standby mode is disabled.',
],
)
def test_permanent_connection_errors_are_non_retryable(self, source, error_msg):