When cascading replication for PostgreSQL across sites is worth the complexity
A cascade is worth its complexity when a remote site needs a standby, the primary is already carrying heavy replication load, and the WAN link cannot absorb one full copy of the WAL stream per remote standby. A cascading standby relays WAL through one intermediate standby, so the primary sends the stream once across the constrained link and the downstream standbys receive it from the intermediate node. The PostgreSQL high availability documentation describes standbys that receive WAL from other standbys, and teams adopt the pattern for exactly these two reasons: less work on the primary and fewer copies of the same WAL crossing the cross-site link. Confirm the exact settings for your PostgreSQL version in the high availability documentation before you design around them.
Before you choose a cascade, measure what you are trying to relieve. Check the WAL generation rate on the primary during peak and batch windows, the sustained bandwidth available to the remote site, and how many standbys would otherwise connect across it. If the link already handles the full stream for one remote standby with headroom, a direct standby is simpler to operate and a cascade adds a hop without a clear benefit. A cascade also does not remove the need for local redundancy at the remote site. Ask whether the intermediate standby itself needs a second standby, because a single relay that fails cuts off every downstream node until someone rebuilds the chain.
The trade-off is a longer and less predictable path for data. Every hop adds lag, and the intermediate standby becomes a dependency for everything beneath it. The cascade also cannot give you synchronous commit guarantees across the WAN, so it fits sites that accept asynchronous delay and not sites that need a commit to wait for a remote copy. Decide early which recovery point and failover behavior the business needs for the remote site, then test the design against those targets. The sections on failover and monitoring show how to handle promotion and lag at each hop.
Cascading replication runs one WAN hop, then fans out locally
The diagram starts at the primary in site A, which streams WAL to an intermediate standby in the same site. That standby relays WAL over the WAN link to a relay standby in site B, which feeds the local standbys in site B. Every arrow is asynchronous, so no commit on the primary waits for any downstream server. Check each hop separately: the WAN link carries the traffic that the relay must absorb, and lag accumulates at every step from the primary to the far standbys.
Each hop is asynchronous, and only the intermediate-to-relay link crosses the WAN.
Choosing a topology by site count and link quality
One remote site with one relay is the simplest cascading layout. The primary streams WAL to a single intermediate standby in the main data center, and that relay forwards the same WAL to the standbys at the remote site. The primary sends one copy of the WAL stream across the WAN instead of one copy per remote standby, which matters most when the remote site runs several replicas. The cost is one extra hop, so the remote standbys always trail the relay, and the relay trails the primary.
- Primary bandwidth: one stream crosses the WAN regardless of how many standbys sit behind the relay.
- Extra hops: one, so replay lag at the remote site adds to the lag already present at the relay.
- Fit: a single remote site with several replicas, or a WAN link that is the bottleneck for the primary.
- Failover effect: if the relay fails, the remote standbys lose their upstream and must be repointed to the primary or another relay.
- Limit: the relay must stay healthy and sized for the forwarding load, so it is a single point of dependency for that site.
Check the measured WAN throughput and the replication lag at each hop before you commit, and confirm how your chosen tooling repoints a downstream standby after an upstream change.
When several remote sites need copies, a single relay can fan out to a second tier of relays, one per site, or to standbys at each site. The primary still sends WAL to only one or a small number of intermediate standbys, so the cost of adding sites lands on the relays and the local links rather than on the primary's uplink. Every added tier increases the number of hops between the primary and the most distant standby, and each hop adds its own replay and transfer delay.
- Primary bandwidth: flat with respect to site count when the primary feeds only the central relay.
- Extra hops: two or more for the farthest sites, so lag accumulates along the chain.
- Fit: several sites with reasonable links to a hub, where each site needs local read capacity or a warm copy.
- Failover effect: a relay failure affects every site downstream of it, so the tree can take out more than one site at once.
- Operations: each relay needs its own monitoring, slot handling and disk sizing for WAL it keeps while forwarding.
Ask how many tiers your recovery design can tolerate and map which sites lose their feed if a given relay is down.
A flat design has every standby connect directly to the primary. There are no intermediate relays, so each standby receives its own WAL stream. This is the simplest topology to reason about and debug, because every standby has one upstream and replication lag is measured against a single source. The trade-off is that the primary's outbound bandwidth and WAL sender load grow with each standby, and remote standbys each pull the same WAL across the WAN.
- Primary bandwidth: scales with the number of standbys, which can be the limiting factor on a constrained uplink.
- Extra hops: none, so the lag on each standby reflects the link to the primary only.
- Fit: a small number of standbys, links that carry the stream comfortably, or a site where a relay would add more failure modes than it removes.
- Failover effect: promotion and repointing are simpler, because no standby depends on another standby for WAL.
- Operations: each standby needs its own replication slot or retention plan on the primary, which adds WAL retention pressure there.
Measure the sustained WAL generation rate and the uplink capacity at the primary, and confirm the number of standbys the primary can feed before the design is final.
Configuration settings that shape a cascade and when each fits
This table compares the PostgreSQL settings that define each hop in a cascade, from the relay's upstream connection to its WAL sender limits and slots. Read each row as a decision about one hop, then check the parameter behavior against the PostgreSQL documentation for your exact major version before you change anything.
| Setting | Role in the cascade | When it fits | Trade-off |
|---|---|---|---|
| primary_conninfo (relay) | Points the intermediate standby at the primary so it can receive and relay WAL | Every cascade, set on the relay to pull from the primary over the WAN link | Only one upstream is active at a time, so the relay itself is a dependency for every leaf |
| primary_conninfo (leaf) | Points each downstream standby at the relay instead of the primary | When leaves should draw WAL from the local site and not cross the WAN | Leaves lag the relay, and a relay outage stops WAL delivery to all of them until repointed |
| hot_standby | Lets the relay and leaves serve read-only queries while replaying WAL | When local read traffic at the remote site is part of the design | Replay conflicts can cancel long read queries, so confirm conflict handling on your version |
| max_wal_senders (relay) | Caps how many downstream connections the relay accepts for WAL streaming | When the number of leaves plus backup and monitoring connections must be planned in advance | Each connection uses resources on the relay, and a low cap blocks new leaves until it is raised and restarted |
| Replication slots per hop | Holds WAL on each upstream until the next standby confirms receipt | When you need a leaf to resume after a short disconnect without a full rebuild | Slots keep WAL on disk while a hop is down, so monitor slot lag to protect disk space |
| wal_level | Must be set to replica or higher on the primary and relay so WAL carries what standbys need | Any streaming setup, and it must be decided before the cluster is built | Changing it requires a restart, and higher levels generate more WAL |
| recovery_min_apply_delay (leaf) | Holds replay on a chosen leaf for a fixed interval behind its source | When one leaf should stay behind to recover from an accidental change | The delayed leaf is not current, so it must never be used for failover targets |
| Recovery target settings | Define where a standby or restored cluster stops replaying WAL | When a leaf is promoted or restored to a specific point after an error | Wrong target settings can stop recovery early, so test them against a copy first |
Why cascading only works asynchronously
A cascade is asynchronous from end to end, and the reason is simple: the primary does not wait for downstream standbys. The intermediate standby receives WAL from the primary and relays it to the standbys beneath it, but a commit on the primary is acknowledged as soon as its own synchronous standbys (if any are configured) confirm it. Cascaded standbys sit outside that acknowledgment path. Any synchronous commit guarantee you configure on the primary therefore covers only the servers that are directly in synchronous_standby_names, not the standbys several hops away. Before you design the topology, confirm in the PostgreSQL high availability documentation how your PostgreSQL major version handles the synchronous settings for cascaded standbys, and write that behavior into your design notes.
For durability and recovery point objectives, the practical consequence is that the downstream site's RPO is the replay lag of the whole chain, not the lag of one link. Each hop adds delay: a record must be received by the intermediate standby, written to its own WAL, and replayed on the downstream standby before that site has it. Under a primary failure, any WAL that never left the primary, or that reached the intermediate standby but not the downstream one, is lost to that site unless you have WAL archiving or a fallback path. Measure lag at every hop under normal load and under peak write load, and set the RPO you are willing to state to the business from those measurements, not from the topology diagram. Synchronous replication decisions, including when a commit waits for a standby, are covered in the sibling topic on PostgreSQL synchronous replication and quorum commit.
Failover follows the same rule. If the intermediate standby fails, downstream standbys keep their position but stop receiving new WAL until you reconnect them to the primary or to another upstream, which is a manual or tool-driven step that must be rehearsed. If the primary fails and a downstream standby is promoted, it may be behind the lost primary by the lag at that moment, so promotion is a conscious data-loss decision. Write the promotion runbook with the question "which standby is allowed to take over, and how much data may be lost in doing so" answered in advance. Ask your team or partner to demonstrate those steps on a test chain before go-live, because a cascade that works on a diagram can still leave downstream sites behind after a real failure.
How to build a cascade step by step with checks
This sequence takes a primary with one or more standbys and adds an intermediate relay standby that forwards WAL to downstream standbys at a second site. Each step ends with a check so you know the hop is working before you add the next one.
Confirm versions and replication roles
Before changing anything, confirm that the primary, the planned relay and every downstream standby run the same major PostgreSQL version, and record the current settings that govern replication, including wal_level, max_wal_senders, max_replication_slots and the archive configuration. The DBA or platform engineer does this on each server, and the output is a written inventory. Check this with SHOW server_version and SHOW wal_level on each host, and confirm the primary is not already relaying to an unexpected standby by querying pg_stat_replication. Ask your team to confirm the exact supported minor release you will target, using the PostgreSQL versioning policy as the reference.
Create the replication role and access rules
On the primary, create a dedicated login role with the REPLICATION attribute and no other privileges, then add pg_hba.conf entries that allow that role to connect from the relay's address only, preferably over TLS. The security engineer reviews the entry and the password or certificate method used. Reload the configuration and confirm the relay can authenticate with a test connection using psql in replication mode. The check is a successful connection from the relay and a reject from any other source address in your test.
Build the relay with pg_basebackup
On the relay host, run pg_basebackup against the primary with the replication role, writing into an empty data directory owned by the PostgreSQL service account. Use the streaming option so WAL needed to make the copy consistent is included. Keep the backup run on a maintenance window your team has agreed, because the copy adds load to the primary and transfers the full data set across the link between sites. The check is that pg_basebackup exits without error and reports the expected size, and that the data directory contains a PG_VERSION file matching the primary.
Configure the relay as a standby
Create the standby.signal file in the relay's data directory and set primary_conninfo to point at the primary using the replication role. Enable hot_standby if read queries should run on the relay, and set primary_slot_name only after the slot exists on the primary. Start the server and confirm it has entered recovery. The check is SELECT pg_is_in_recovery() returning true on the relay, and a row in pg_stat_wal_receiver showing status streaming with the primary's address.
Create slots and attach downstream standbys
Create a physical replication slot on the relay for each downstream standby, and set max_replication_slots and max_wal_senders on the relay high enough for every hop. Every downstream standby is then built with pg_basebackup from the relay, using the same replication role or a role your team defines on the relay, and configured with its own standby.signal and primary_conninfo pointing at the relay. The check is a row for each downstream standby in pg_stat_replication on the relay, with state streaming and its slot name in the output.
Verify each hop and its lag
Verify every hop as its own link: on the primary, confirm the relay appears in pg_stat_replication with its sent, write, flush and replay positions. On the relay, confirm the downstream standbys appear in pg_stat_replication and that their replay positions move forward after a test write on the primary. Compare the LSN positions across all three hosts to measure lag at each hop. Record these baseline values so later monitoring has a reference point. The check is that a test row written on the primary becomes visible on the most distant standby, and the lag at each hop is recorded.
Test relay failure and downstream behavior
Stop the relay in a controlled test and observe what the downstream standbys do: they stop receiving WAL and report disconnection in their logs and in pg_stat_wal_receiver. Confirm the primary still reports its own slot and that WAL retention on the primary grows while the relay is down. Restart the relay and confirm the downstream standbys reconnect and catch up. Document the procedure your team uses to repoint a downstream standby to the primary or another relay if the relay is not coming back. The check is a recorded test result showing the downstream standbys resumed streaming after the relay returned.
Set up monitoring for each hop
Add alerts for each link: replication state and replay lag from the primary's view, the relay's receive status and replay lag, and the downstream standbys' receive status. Include alerts on the disk used by WAL on the primary and the relay, since a stalled hop causes WAL to accumulate. Your monitoring team confirms that each alert fires in a test. The check is that a deliberate pause of the relay triggers the alert for the downstream hop within your agreed threshold, and that the alert clears after recovery.
What happens downstream when the relay or primary fails
A cascading topology adds a failure point that a flat cluster does not have: the intermediate standby that feeds other standbys. Each card below describes a failure case, what the downstream standbys do, and what to check before go-live, since PostgreSQL itself does not detect a failed primary and needs external tools to act on it.
Relay failure stalls downstream standbys
When the intermediate standby stops, the standbys below it receive no new WAL and fall behind the primary without any error on the primary side. Downstream standbys keep serving their last applied state, so read traffic may return stale data without an obvious alert. Check that each downstream standby reports its replay lag, and decide in advance whether they should reconnect directly to the primary or wait for the relay to return.
HA docsPrimary failure needs an external detector
PostgreSQL does not notice that the primary has failed or tell a standby to take over, so detection and promotion come from an external tool or a runbook. In a cascading layout, the tool must know which standby sits behind the relay and which can be promoted. Confirm the tool's health checks see the whole chain, not only the direct standby.
Failover docsPromoting a current standby
If the promoted standby has replayed all WAL that the old primary had sent, promotion loses no committed transactions beyond what asynchronous replication never delivered. Compare replay positions across candidates before promoting. Downstream standbys can then be repointed to the new primary, and their replay positions should advance once they reconnect.
Promoting a standby that is behind
A standby that lags the old primary will be promoted with missing transactions, and those transactions are lost from the new primary's history unless recovered from elsewhere. Record the lag at the moment of failure, decide whether the business can accept that loss window, and rehearse the loss report. Candidate selection should weigh lag against location, since a nearby but behind standby may be worse than a distant current one.
Timeline divergence after a failover
When an old primary returns after a standby was promoted, its WAL history can diverge from the new primary's. Replaying the old primary as a standby then fails until it is rebuilt, or repaired with archive recovery and a timeline switch. Plan for a pg_basebackup rebuild or a documented archive-based recovery, and confirm the WAL archive is reachable from every site before an incident.
Archiving docsRe-pointing the chain after promotion
After promotion, the downstream standbys must follow the new primary or the surviving relay, and the chain may need a new relay. Each hop needs its replication user, pg_hba.conf entry and connection settings updated, and replication slots on the relay must still exist. Test this path in a lab, because a missed hop often shows up only as lag that grows silently.
Questions teams ask before building a cascade
What drives the cost and effort of a PostgreSQL cascade?
Effort comes mostly from the number of hops, the number of sites, and how much monitoring and runbook work each hop needs, not from the replication setting itself. Each intermediate standby is another server to size, patch, secure and watch, and each cross-site link needs its own network review. Cost recurs in operations: someone must check lag on every hop, keep primary_conninfo and slot settings correct after changes, and rehearse failover paths. Ask any quote to separate one-time design and build work from ongoing support, and to state which hosts, sites and monitoring stacks are included.
How long does a cascade build take, and what does the timeline depend on?
The timeline depends on the number of sites, whether the network paths between them are already approved, how large the initial base backup is, and how much of the monitoring and failover testing is in scope. Copying the data is often the longest single step, and it scales with database size and the bandwidth available for the copy. Change approvals and firewall work on cross-site links frequently take longer than the database work. Ask for a schedule that lists these dependencies as separate milestones, and do not accept a duration that is not tied to your environment.
What must our team provide before a cascade can be built?
Your team provides network paths and firewall rules between each hop, server capacity and storage for each intermediate standby, DNS or service names, TLS certificates, and the replication role and pg_hba.conf entries that allow each standby to connect upstream. You also need monitoring access, an alert destination, and a named owner for each hop. Runbooks are a required input, because operators must know which standby to promote and how to repoint downstream standbys after a change. Confirm sizing assumptions with your own workload data before the design is approved.
Can our in-house team build and run a cascade without a partner?
Yes, if the team already runs streaming replication and has tested failover in its own environment. A cascade adds an intermediate hop, so the engineers need to understand how WAL moves through each standby, how lag accumulates, and what happens to downstream standbys when an upstream standby is promoted. Teams without that experience usually benefit from a written design review and a failover rehearsal before go-live. Compare the partner quote against the hours your own engineers would spend on learning, testing and on-call coverage, and check whether your current staff has capacity for both.
How do cascading standbys work with backups and point-in-time recovery?
A cascade does not replace backups. Point-in-time recovery depends on a base backup plus archived WAL files, and a standby that receives changes from the primary still reflects any accidental change, such as a dropped table, within seconds. Keep continuous archiving configured on the primary or another source you control, and test restores on a separate host. Incremental backups taken with pg_basebackup can be combined at restore time with pg_combinebackup, which is a separate workflow to plan and verify. Confirm which node runs base backups so the backup load does not fall on the hop that serves downstream standbys.
Does a cascade replace a cross-region disaster recovery standby?
No. A cascade relays WAL through an intermediate standby to reduce load and cross-site bandwidth, but it is still asynchronous replication that depends on the upstream chain. If the site hosting the upstream hop is lost, downstream standbys may need to be repointed, and any changes not yet received are lost unless WAL archives are available. A cross-region disaster recovery standby is a separate design with its own promotion runbook, recovery point and recovery time targets, and DNS or application cutover. Many teams run both, and each needs its own testing. Ask any vendor to show how each design behaves when a whole site is unavailable.
Is a cascade the right choice when we need synchronous commit?
A cascade cannot provide synchronous commit across hops. The asynchronous-only limit means a commit on the primary does not wait for standbys in the cascade, so a cascade is not a way to get zero data loss on failure. If your requirement is that no committed transaction may be lost, synchronous replication must be designed at the primary level, and the cascade becomes a read or distribution layer on top. Confirm your recovery point objective with the business owner before choosing the topology, since that decision changes the whole design.
Securing replication traffic across sites
Every relay hop in a cascading topology is a place where WAL, credentials and base backups cross a network boundary. The cards below cover the controls that decide who can pull WAL from each tier, how that traffic is encrypted and authenticated, and where archived copies of the data are readable.
Scope the replication role
A standby connects with a role that has the REPLICATION attribute and nothing more. Create a dedicated role per relay tier rather than reusing an application or superuser account, so a compromised relay can be revoked without touching client access. Check that the role cannot log in to application databases and that its password or certificate is rotated on a schedule your team can actually run. Confirm the role's privileges with your PostgreSQL DBA before the first standby connects.
Authentication methodsTLS for WAN relay hops
A relay that streams WAL over a WAN link carries table data in readable form unless the connection is encrypted. Set ssl = on on the upstream server and require sslmode=verify-full in the standby's primary_conninfo, so the standby checks the upstream certificate's chain and host name. Plan certificate issuance and renewal for every relay, since an expired certificate will stop a cascade silently until lag alerts fire.
Certificate authentication between tiers
Client certificate authentication lets a relay prove its identity with a key pair instead of a shared password. PostgreSQL documents certificate as one of its client authentication methods, and it fits relays that need to be revoked individually. Decide who issues relay certificates, where private keys are stored and how revocation reaches the upstream server. Confirm with your security team which certificate authority your policy accepts before you design the trust chain.
Scope `pg_hba.conf` per relay address
Write replication entries in pg_hba.conf that name the relay's exact address range and the replication database keyword, and reject everything else. A broad entry such as a whole data center subnet lets any host in that range request a base backup or stream WAL. Keep one line per relay tier, use hostssl so plain connections are refused, and reload the configuration after each change. Review these entries whenever a relay is added or retired.
Control access to archives and base backups
Archived WAL and base backups hold the same data as the cluster, and a relay that restores from an archive can read everything in it. Restrict read access on the archive bucket or file share to the restore identities, enable encryption at rest, and log every read. Point-in-time recovery depends on this archive, so the people who can read it are part of your recovery design, not a separate storage concern. Ask your backup owner which accounts can list and download archived files.
Continuous archiving docsHow DeployOpen scopes and delivers cross-site PostgreSQL replication
DeployOpen plans, builds, tests and hands over cascading replication for PostgreSQL inside infrastructure you control, including your cloud accounts, data centers or air-gapped networks. The work starts with a written scope that names every hop, the sites involved and the failover behavior you need to prove before go-live.
How we scope
- Map the primary, intermediate standby and downstream standbys to named sites, networks and hosts you control.
- Record which sites hold WAL relays, which hold read-only copies and where asynchronous lag is acceptable.
- Agree in writing whether the engagement covers the topology design, the build, the failure tests or all three.
How we build
- Configure the upstream primary, relay standby and downstream standbys with replication roles, pg_hba.conf entries and TLS.
- Set up WAL archiving and a base backup path so each hop can be rebuilt without touching the primary.
- Add monitoring for replay lag and connection state at every hop, with alerts agreed with your operations team.
How we hand over
- Deliver the topology diagram, configuration files, runbooks for promoting a downstream standby and lag thresholds.
- Run the agreed failure tests, such as stopping the relay and promoting a downstream node, and document the results.
- Walk your operators through the runbooks so they can run promotion and rebuild steps without DeployOpen present.
How we support
- Engagements are fixed-scope, so changes to topology or sites are priced through a written change to the scope.
- Ongoing support, upgrades and continuous testing are available as a retainer for clusters that change over time.
- Confirm with DeployOpen which PostgreSQL major version and minor release your clusters will run before the build starts.

