Read your own writes, off the primary
The modern application architecture shifts the challenges associated with database replication lag to the frontend, making it more difficult to manage. When a user makes a change, it is processed in parallel with other tasks, leading to inconsistencies across different tabs and devices. To address this, PostgreSQL 19 introduces a way to query the replication lag on the standby database.
By using the `WAIT FOR` statement, developers can control when a read operation waits for the standby to process the data. This allows for better handling of replication lag and ensures that reads are served correctly. Remote_apply is the setting that best resolves the lag issue, as it makes every commit on the primary wait for replay on the standby, ensuring that the data is visible to queries.
The configuration of the standby's replay mode and timeout settings further optimize the performance by ensuring that the reads are directed to the primary when needed.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.