A successful write on an asynchronous PostgreSQL primary does not guarantee the next read will see it on a standby. Route consistency-sensitive reads to the primary, or use a proven replay boundary with a bounded wait and clear fallback. Keep replica reads where the product can tolerate a known level of staleness.
One invoice, two servers and a fresh read
We ran a PostgreSQL 18.6 primary and a physical streaming standby in one disposable container. Both used local sockets. After the empty invoice table had reached the standby, we paused replay, confirmed the paused state, then committed one row on the writer. With no other application writes, we recorded the writer’s current WAL position after the commit.
| Order | Connection and action | Observed invoice rows |
|---|---|---|
| 1 | Writer commits INV-42; fresh read on the primary | 1 |
| 2 | Fresh read on the standby with replay paused | 0 |
| 3 | Same standby after replay crossed the recorded boundary; fresh read | 1 |
The middle read returned zero for an invoice the primary already had. For a redirect immediately after creation, route the detail request to the writer or wait for the selected standby to replay that boundary before starting a fresh read. Once we resumed replay and verified its position, the standby returned one row. We induced the delay to control the order. These observations establish visibility, not typical replica lag or a production timeout.
Follow the relevant server state
A WAL record is generated on the primary, sent to the standby, stored, and replayed. These stages describe different progress. Data that has reached the standby may still await replay. For a read-after-write contract, ask whether the change is visible to a new query on the chosen server. Log-Shipping Standby Servers describes asynchronous streaming and the progress available through replication status and log positions.
Imagine an application creates an invoice and immediately redirects the user to its details. If the second request lands on a lagging standby, it can receive “not found” although the operation committed successfully. Retrying invoice creation would be a second write, and the stale read did not establish that it was necessary.
Pick a read policy per path
A short editing workflow can send its follow-up reads to the current writer. This spends primary capacity where the application needs an immediate answer. A read-only report can continue using a replica if the interface states how fresh it is and the lag is within its operational limit.
A stronger option is to carry a log position known to be at or beyond the write's commit. Wait until the selected standby's replay progress has reached the position, then begin a read with a fresh snapshot. Establish how the position is obtained and compare it only in the appropriate replication lineage. A timeout should have a deliberate fallback, such as reading the writer, returning a pending state, or returning a retryable error. An indefinite wait turns stale reads into accumulated requests.
Interpret lag measurements carefully
A byte gap tells you how far apart two reported log positions are. It does not convert directly to time without workload information. A timestamp for the last replayed transaction can look old on an idle system when nothing new needs to be applied. Combine location, activity and the user-facing symptom before deciding the standby is unhealthy.
Synchronous replication can change which step the commit waits for, depending on configuration. A remote-apply policy can wait for replay on participating synchronous standbys, with consequences for write latency and availability. Confirm which servers acknowledged the transaction and which can serve the user's read.
Verify the policy with one controlled delay
Use a disposable environment to reproduce the invoice flow while slowing replica apply. Observe the writer and the chosen replica, then verify both the successful replay path and the timeout behavior. Account for fresh transactions, reconnects and failover. The connection pool guide addresses another part of the reading path: tuning pool capacity. More connections by themselves cannot make a standby apply a commit sooner.