PostgreSQL read replicas: understand lag and read-only limits
A PostgreSQL read replica is a separate server that follows WAL changes from the primary while serving read queries. It can move reports and other read-heavy work off the primary, but default replication is asynchronous, so recent changes may not yet be visible. Treat it as a query target with freshness and read-only constraints, not as an instantly identical extra server.
This article follows PostgreSQL 19 documentation reviewed on 23 November 2026. It covers physical streaming standbys used for reads; provider-specific endpoints, routing proxies, and automated failover are outside scope.
How is a read replica different from a backup or failover?
PostgreSQL hot standby accepts connections and read-only queries while recovering or following a primary. The primary creates WAL; the standby receives and replays it. This deployment can add read capacity. It is not a backup: an accidental table deletion on the primary is replayed to the replica too. A standby may also be promoted during a separate failover procedure, but promotion, fencing the old primary, and changing client traffic are distinct operations. PostgreSQL 19: Hot Standby · Warm Standby · High Availability
Which work fits a read replica?
Queries such as SELECT and COPY TO are allowed. DML (INSERT, UPDATE, DELETE, MERGE, COPY FROM), DDL, sequence changes such as nextval() and setval(), and SELECT ... FOR UPDATE are not. Temporary tables do not make writes permissible; some commands allowed in ordinary read-only transactions, such as LISTEN and NOTIFY, are also restricted. You cannot create an index or run ANALYZE only on the standby. Hot Standby restrictions
A replica can isolate dashboards or reports from primary query load, but it consumes its own CPU, memory, disk I/O and network. A large primary write workload creates WAL that must be replayed and can compete with replica queries. Adding a server does not automatically make every query faster.
| Workload need | Fit | Reason |
|---|---|---|
| Dashboard that tolerates a short delay | Often | Read work can move, but monitor freshness and replica capacity |
| Show a user's just-saved change immediately | Not by default | Async replay may still be behind |
| Writes, DDL, or sequence updates | No | Hot standby is read-only |
| Long reports during frequent VACUUM/DDL | Conditional | WAL replay may cancel queries or fall behind |
Why can results be stale?
The primary writes changes to WAL and the replica receives and replays them afterward. With asynchronous replication, a read shortly after commit can therefore see an older snapshot. Once a commit record is replayed, new snapshots on the standby can see it. For example, after a customer saves a delivery address on the primary, an immediate order-page read from a lagging replica could briefly show the former address. A catalog report may tolerate a delay; a confirmation page often should read from the primary or wait for replay.
PostgreSQL 19 documents a read-your-writes method: after commit, obtain the change's WAL location on the primary, pass it to the standby, and wait there until replay reaches that location:
-- On primary, after the write transaction commits:
SELECT pg_current_wal_insert_lsn();
-- On standby, with the actual LSN returned above:
WAIT FOR LSN '0/306EE20';The LSN is dynamic, not a fixed value to copy. A successful wait means changes through that location have been applied, so a subsequent query can see them. The application must handle waiting time and connection errors. This offers consistency for selected requests without making every commit synchronous. Read-Your-Writes Consistency
Why can long replica queries be canceled?
DDL or VACUUM on the primary can generate WAL actions that conflict with a long-running standby query. The primary does not wait for queries it cannot see on the standby; the standby must apply WAL to stay current. PostgreSQL can delay replay up to max_standby_streaming_delay or max_standby_archive_delay, then cancel conflicting queries. Longer waits preserve queries but increase replica lag. Query conflicts
hot_standby_feedback can prevent some cleanup conflicts, reducing cancellations, but it delays dead-row cleanup on the primary and may cause table bloat. Measure cancellations and lag together before changing it. The standby's pg_stat_database_conflicts shows cancellation counts and reasons.
What should you monitor and when should you choose one?
On the primary, pg_stat_replication shows each directly connected standby's state and sent, written, flushed and replayed WAL positions. replay_lag approximates how long recent changes take to become query-visible; it is not a prediction of future catch-up time. On an idle, fully caught-up system it may become NULL, so do not always interpret NULL as zero lag. Pair it with LSN progress, last reply time and the application's freshness tolerance. Monitor pg_stat_database_conflicts on the standby for canceled reports. Replication statistics
Choose a read replica when measurements show a primary read bottleneck, the selected workload can tolerate its freshness behavior, and you can operate the extra capacity. Compare query/index improvements or caching first. Route read-after-write requests to the primary or use the documented LSN wait. A replica alone does not provide backups, automatic failover, or a complete read/write load balancer.
This guide covers PostgreSQL 19 core behavior, not a provider-specific implementation. No live replica or lag measurement was tested.
Sources
[PostgreSQL 19: High Availability](https://www.postgresql.org/docs/19/high-availability.html)
[PostgreSQL 19: Warm Standby](https://www.postgresql.org/docs/19/warm-standby.html)
[PostgreSQL 19: Hot Standby](https://www.postgresql.org/docs/19/hot-standby.html)
[PostgreSQL 19: Monitoring Statistics](https://www.postgresql.org/docs/19/monitoring-stats.html)