r/postgres • u/shibi__dev • 11d ago
Discussion PostgreSQL 19: Read from Replicas Without Missing Recent Writes
PostgreSQL 19 introduces WAIT FOR LSN, helping applications handle replication lag in asynchronous replicas.
When an application writes data to the primary database and immediately reads from a replica, the latest changes may not yet be available.
WAIT FOR LSN allows the replica to wait until it has replayed the required changes before processing the read.
In simple terms: Write to the primary → Wait for replication → Read from the replica.
This makes read-your-writes consistency easier to achieve without routing every read to the primary.
#PostgreSQL #DatabaseEngineering #SystemDesign #SoftwareEngineering
1
u/addy3006 6d ago
Nice, this has been a pain point for a long time. Does it work with the standby's replay position only, or can you also use it on a cascading standby? Curious how people will pass the LSN from the write to the read in practice, probably through the session or a cookie.