Droplet → Managed PostgreSQL: Standby readiness timing after automatic failover
0 reputation · 05 Aug 2024, 12:56 UTC
0 reputation · 05 Aug 2024, 12:56 UTC
The goal is to determine how long a DigitalOcean Managed PostgreSQL cluster remains in a write‑unavailable state after the primary node becomes unreachable and failover is triggered.
Network latency between the Droplet and the database can skew measurements, and the synchronization period of the standby varies by PostgreSQL version and cluster configuration. The documentation does not specify an exact window during which the standby is catching up.
While the cluster status endpoint reports the current role of each node, it is unclear whether a change to "standby" immediately implies that the node accepts write connections, or if there is an intermediate period of replication lag that temporarily blocks writes.
33775 reputation · 05 Aug 2024, 20:46 UTC
After a primary node becomes unreachable, DigitalOcean’s Managed PostgreSQL cluster initiates a failover. The new standby promotes to primary only after it has replayed the WAL backlog and reached a consistent state. In practice the node is write‑unavailable for roughly 30–60 seconds, though the window can grow to several minutes if the replication lag is large or the cluster is heavily loaded.
Call /v2/databases/{id}/status (or /v2/databases/{id}/replication). The promoted node will report:
{
"role": "primary",
"state": "running",
"replication_lag": 0
}
Only when role is primary, state is running, and replication_lag is zero should the node be considered write‑ready.
From any client connected to the cluster, run:
SELECT pg_is_in_recovery();
It should return false on a ready primary.
The server logs the line "database system is ready to accept connections" once the promotion completes. Monitoring tools can tail this message or query pg_stat_replication for write_lag=0 and state='streaming'.
Attempt a simple INSERT or UPDATE and verify that the transaction commits without a could not connect to server error.
database_cluster_status metric – it flips to running when the primary is ready.pg_stat_replication and alert when write_lag is zero and state is streaming.pg_is_in_recovery() every minute and logs the result; a transition from true to false marks readiness.role='primary' and state='running' appear.SELECT pg_is_in_recovery(); – expect false.What PostgreSQL version is running in your Managed PostgreSQL cluster? The replication lag behavior and API schema can differ between major releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.