Skip to content

Commit 595a70e

Browse files
tilloclaude
andcommitted
ha-recorder-pg: enable synchronous replication (preferred durability)
A graceful CNPG failover under async replication (maxSyncReplicas=0) drops the recorder's last unreplicated writes on promotion. HA's in-memory recorder session then references rows the new primary never received, producing a sqlalchemy StaleDataError loop that freezes the recorder until HA restarts. Observed 2026-06-22 22:04 UTC: pg-3 (primary) gracefully restarted for node maintenance, pg-2 promoted at 22:04:52; last good recorder write was 22:04:05, 47s earlier and not yet replicated -> recorder frozen ~8h, recurrent across failovers. synchronous {method: any, number: 1, dataDurability: preferred} makes commits wait for the standby (RPO 0, lossless failover) while falling back to async if the standby is down so HA writes never stall. CNPG 1.29.1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013aFYGqPQhb4JqsnC6USdHQ
1 parent 4bf7d76 commit 595a70e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

home-assistant/ha-recorder-pg.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ spec:
5757
## room and keep WAL modest.
5858
maintenance_work_mem: 128MB
5959

60+
## Synchronous replication so a CNPG failover is lossless (RPO 0): the
61+
## primary waits for the one standby to confirm each commit before it
62+
## returns. The default (async, maxSyncReplicas=0) drops the last
63+
## unreplicated writes on promotion; HA's in-memory recorder session then
64+
## references rows the new primary never received -> a sqlalchemy
65+
## StaleDataError loop ("expected to update N rows; M matched") that
66+
## freezes the recorder until HA is restarted. Root cause of the
67+
## 2026-06-22 22:04 UTC ~8h silent recorder freeze, and recurrent across
68+
## node-maintenance failovers. dataDurability: preferred falls back to
69+
## async when the standby is unavailable, so HA writes never stall on a
70+
## missing replica (availability favoured over strict RPO for a 2-node
71+
## cluster). Requires CNPG >= 1.25 (operator is 1.29.1).
72+
synchronous:
73+
method: any
74+
number: 1
75+
dataDurability: preferred
76+
6077
bootstrap:
6178
initdb:
6279
database: homeassistant

0 commit comments

Comments
 (0)