PostgreSQL 19: Read-Your-Writes Without Sync Tax
Alps Wang
Aug 26, 2026 · 2 views
Bridging the Asynchronous Replication Gap
The introduction of WAIT FOR in PostgreSQL 19 is a genuinely innovative solution to the persistent 'stale read' problem in asynchronous replication setups. By allowing sessions to block until a specific WAL LSN is replayed on a replica, it provides the 'read-your-writes' consistency that developers have long sought without resorting to the performance-degrading synchronous replication. The ability to specify different MODE options (replay, flush, write) offers fine-grained control over the consistency guarantees, catering to various application needs. Furthermore, the decision to implement WAIT FOR as a top-level command, circumventing snapshot mechanisms, is a crucial technical insight that explains its decade-long journey to implementation and prevents self-deadlocks. This feature directly addresses a pain point for many application developers and database administrators working with distributed PostgreSQL setups, offering a more elegant and performant alternative to application-side polling or synchronous commits.
However, potential limitations and concerns warrant consideration. The article correctly notes the caveat regarding timeline awareness after a promotion; users must be vigilant about this when failover occurs. While WAIT FOR avoids the 'synchronous replication tax' on writes, it introduces a latency cost to specific read operations that require this consistency guarantee. The choice of LSN to wait for, particularly using pg_current_wal_insert_lsn(), is conservative but might still involve waiting for WAL that isn't strictly necessary for a given read if the application's understanding of its write is slightly out of sync with the exact LSN. The TIMEOUT and NO_THROW options are essential for production robustness, but their effective usage will require careful tuning. The reliance on application-side logic or proxies to manage LSNs and inject WAIT FOR commands means that the transparency of 'read-your-writes' consistency will depend heavily on the implementation details of these intermediary layers. For developers not using such tools, direct application-level integration of WAIT FOR will still require careful planning and error handling.
This feature will significantly benefit applications that require strong read-your-writes consistency on replicas, especially those that cannot tolerate the performance overhead of synchronous replication. This includes many e-commerce platforms, financial services applications, and any system where immediate visibility of newly written data on read replicas is critical for user experience or data integrity. Database administrators managing read-heavy workloads with replicas will also find this invaluable for optimizing read performance while maintaining necessary consistency levels. The potential for connection poolers and protocol-aware proxies to transparently handle this for applications makes it a compelling upgrade path. The technical implications are substantial, potentially leading to simpler application architectures that can leverage asynchronous replication more effectively for both scaling reads and ensuring data visibility.
Key Points
- PostgreSQL 19 introduces
WAIT FOR, a new command to achieve 'read-your-writes' consistency on asynchronous replicas. - It allows a session to block until a specific WAL LSN has been replayed on a standby, avoiding the performance penalty of synchronous replication.
WAIT FORcan be configured with different modes (standby_replay,standby_flush,standby_write,primary_flush) for granular control.- The command is designed as a top-level utility statement to prevent snapshot-related deadlocks, a key technical insight behind its long development.
- This feature benefits applications needing immediate data visibility on replicas without compromising write performance.
- Connection poolers and proxies can leverage
WAIT FORto transparently provide read-your-writes consistency to applications.

Related Articles
Comments (0)
No comments yet. Be the first to comment!
