PostgreSQL 19 adds WAIT FOR LSN for read-your-writes on replicas
PostgreSQL 19 introduces the WAIT FOR LSN command, which blocks a replica until it has replayed a given WAL position, solving read-your-writes staleness. PHP tests showed 0 stale reads out of 5000 versus 5000 out of 5000 without WAIT, but there are caveats: the LSN can't be bound, WAIT must be the first statement in a transaction, and pg_current_wal_insert_lsn can hang at WAL page boundaries.
- Without WAIT all 5000 replica reads were stale; with WAIT, 0
- Median wait 315 µs idle and 1.2 ms under write load
- LSN can't be bound: only works with ATTR_EMULATE_PREPARES
- pg_current_wal_insert_lsn timed out 5 of 5000 times at page boundaries
Read next
Software