1 day ago · Tech · 0 comments

Postgres 19 finally gives us a clean way to do read-after-write across replicas. Without it, here’s the problem: you write a row to the primary then you immediately read it back and that query goes to a replica but the replica hasn’t replayed the write yet, so you get stale data or nothing at all The usual workarounds are: sleep after the write and hope the replica caught up (terrible, don’t do it) pin the user to the primary for a few seconds or poll the replica until the write shows up The new WAIT FOR LSN command replaces all of that. It lets the replica block until it has replayed up to your write. MySQL has had this for ages with SOURCE_POS_WAIT() ; Postgres never did, so I’m glad to see it land in Postgres 19 beta 1 . Of everything in this release, it’s the feature I’m most excited about. Reproducing the stale read # A stale read only shows up when there’s real replication lag, so reproducing one needs real replication. The setup here is two Postgres containers running locally…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.