Read replicas
A read replica is a standby Postgres instance that streams changes from the primary and serves read-only queries. Use replicas for read-heavy workloads, analytics queries that should not compete with production traffic, and reporting tools that must not write.
To add a standby, refer to Configure high availability.
Endpoints
Section titled “Endpoints”A database has one endpoint for each kind of traffic. Select one in the Connect dialog under Primary, Standbys, or Any.
| Connect option | Host prefix | Serves |
|---|---|---|
| Primary | pg-<name>-rw | Reads and writes. The endpoint follows a failover. |
| Standbys | pg-<name>-ro | Reads only, load-balanced across standbys. |
| Any | pg-<name>-r | Reads only, across every instance. |
Point your app’s main connection at -rw, and read-only consumers at -ro. A write to -ro fails.
flowchart LR APP[Your app] -->|reads + writes| RW[["pg-name-rw"]] RPT[Reporting / analytics] -->|reads only| RO[["pg-name-ro"]] RW --> P[(Primary)] RO --> S1[(Standby 1)] RO --> S2[(Standby 2)] P -.->|stream| S1 P -.->|stream| S2
Replication lag
Section titled “Replication lag”A row written to the primary can take time to appear on a standby. A read from -ro after a write can return old data. Code that reads its own writes must use -rw.
The replication mode sets whether a commit waits for a standby. The default is Async. For the other modes, refer to Choose a replication mode.
Each standby is a full copy of the database, with the same storage, CPU, and memory. A primary with two standbys uses about three times the resources of a single instance.
Related resources
Section titled “Related resources”- Add database users - Create a read-only login for a reporting tool.
- Monitor a database - Watch the Replication lag panel.
- Troubleshooting Orchard - Fix reads that return old data.