Why a delayed standby helps when a delete reaches production
When a dropped table or bad update has already replicated to every standby, the copies you have are all past the mistake. A delayed standby is a replica configured with recovery_min_apply_delay, so it receives WAL from the primary immediately but holds back applying it for a set interval. Teams add one when they want a copy of the database as it stood a few hours earlier, close enough to extract the lost rows or roll back a bad change without restoring the whole cluster. The delay is the window in which a mistake can be noticed and the pre-error data can still be read from the standby.
A delayed standby is a recovery aid that sits alongside tested backups and point-in-time recovery, not in place of them. It does not protect against everything: a DROP DATABASE or a corrupted filesystem on the primary may still be followed by a delayed copy that has to be handled carefully, and the delay only helps if someone notices the mistake before the replay window closes. Point-in-time recovery from a base backup and archived WAL remains the mechanism you rely on for an arbitrary target time, and that path still needs regular restore tests. Confirm the exact apply semantics, including how the delay interacts with promotion and hot standby queries, against the PostgreSQL documentation on standby servers, which is the reference for this behavior.
Before you commit to the design, confirm which PostgreSQL major version you run and read the standby configuration reference for that release, since behavior around delayed apply is the detail most worth checking against your own version. Ask who is responsible for noticing a mistake within the delay window, because a delayed replica that nobody monitors gives little benefit. Decide whether the standby is a dedicated recovery target or also serves reads, since queries on a delayed replica will see data from the past. These decisions shape the delay value, the WAL retention you must fund on the primary, and the runbook your operators follow under pressure.
Configuration choices and when each fits
This table compares the main choices for a delayed standby: how long to hold changes back, whether the delayed node is dedicated or also serves other roles, how the primary keeps WAL for it, and where archive-based recovery fits. Read each row for the condition that favors it and the trade-off it brings, and confirm the exact settings against the PostgreSQL version you run.
| Choice | Option | When it fits | Trade-off |
|---|---|---|---|
| Delay length | Short delay (minutes to a few hours) | Teams whose most likely error is noticed quickly, such as a bad batch job caught by monitoring | Less time to notice a dropped table before the delay has passed, so the window for correction may close first |
| Delay length | Long delay (many hours) | Teams that often find errors late, such as after a business day or a scheduled report | Holds more WAL on the primary and makes the replica less current for any failover that needs fresh data |
| Standby role | Dedicated recovery replica | Clusters where the delayed copy exists only for recovery and must never receive client traffic | Consumes hardware and storage with no read capacity in return |
| Standby role | Delayed member that also serves reads | Teams that want to use the hardware, with reads that tolerate the delayed data | Readers see stale data by design, and application teams must know the delay exists |
| Standby role | Delayed member eligible for promotion | Rarely advisable, since promoting it returns the bad change if the delay has not yet passed | Failover tooling may promote it by mistake, so exclude it from automatic promotion |
| WAL retention on primary | Retain WAL for the full delay with slots | Delayed standby uses a replication slot and the disk can hold the required WAL | A stalled or abandoned slot can fill the primary's disk, so monitor slot lag and set a size limit |
| WAL retention on primary | Retain WAL with wal_keep_size only | A fixed WAL budget is preferred over a slot with no size limit | The standby falls behind and must rebuild if it needs WAL older than the budget |
| Archive-based recovery | WAL archive and base backups as complement | Any delayed-standby design, since the archive covers damage older than the delay or beyond the standby's retention | Recovery is slower to run and needs its own tested restore procedure |
| Archive-based recovery | Point-in-time recovery only, without a delayed standby | Teams with tested archive restores and acceptable restore times for their recovery targets | Restoring a full base backup and replaying WAL takes longer than promoting a delayed standby |
Choosing the delay length against your recovery window
The delay is a trade-off between how long a mistake can hide and how much disk and data the setup costs. Each card below is a question the team answers from its own incident history, storage budget and failover needs, and the answers together set the delay value.
How long do mistakes stay hidden?
Review past incidents and record the gap between each bad change and its discovery, including changes found by a batch job, a customer report or a monthly reconciliation. The delay must exceed the longest gap you have seen, with margin, or the bad change reaches the standby before anyone notices. Ask whether the people who would notice work on weekends, since a Friday change may surface on Monday. The delay has to outlast discovery, not the average case.
How much WAL must the primary keep?
A delayed standby holds back replay, so the primary cannot recycle WAL the standby still needs. Estimate daily WAL volume from your monitoring, multiply by the delay in days, and add headroom for backups and other consumers. Confirm the disk budget on the primary and whether replication slots or archiving will keep WAL longer than the delay itself. An unplanned slot can fill the disk faster than the delay you chose.
How much data is lost from the copy?
A delayed standby is always behind by the delay length, so any write made in that window is absent from it. Ask which tables and business events would be missing if you recovered from the standby at the moment of the mistake, and whether the application can reconcile those writes afterward. Write this down as the acceptable data gap for each system, since a long delay can make the standby useless for some recoveries.
Can the standby serve during an outage?
A standby that replays with a delay is not a good failover target for ordinary outages, because promoting it means accepting the delay as data loss. Decide whether this replica is a dedicated recovery copy or also a candidate for failover, and keep a separate synchronous or asynchronous standby for that role. Confirm in writing which role the delayed node plays so that operators do not promote it during an incident by mistake.
Does point-in-time recovery cover the gap?
Compare the delayed standby with a tested point-in-time recovery from a base backup and archived WAL. Point-in-time recovery can target any moment in the retention window and does not hold a live copy, but restore takes time that you must measure. Run a timed restore of your largest database to learn whether the standby is needed at all. The standby is faster to reach, while restore is cheaper to run and covers more history.
Continuous archiving docsSetting up a delayed standby step by step
This sequence builds a standby that replays WAL on purpose after a set delay, confirms the delay is working, keeps the primary retaining the WAL it needs, and proves a recovery works before an incident forces one.
Confirm the primary and replication prerequisites
Before touching the standby, the DBA confirms the primary has a replication role, a pg_hba.conf entry allowing that role from the standby's address, and wal_level set high enough for streaming replication. Check the parameter names and syntax in the PostgreSQL high availability documentation, since the exact settings depend on your major version. The step is done when a test connection with the replication role succeeds from the planned standby host.
Create the standby from a base backup
Run pg_basebackup from the standby host against the primary, using the replication role and with the standby configuration written by the tool, so the data directory is a copy of the primary at a known point. Make sure the standby's standby.signal file is present and that the target directory is owned by the PostgreSQL service account. The step is done when the data directory exists, the server starts in standby mode, and the log shows it connected to the primary.
Set the apply delay in standby configuration
Add recovery_min_apply_delay to the standby's configuration, with the value chosen from your recovery window and your storage budget for retained WAL. Keep the delay in the standby's own settings rather than the primary's, and record the value in your runbook with the reason for it. Reload or restart the standby as the parameter requires, and confirm the exact syntax in the PostgreSQL high availability documentation. The step is done when SHOW recovery_min_apply_delay on the standby returns the value you set.
Verify the standby is replaying behind the delay
Create a test row on the primary, then query the standby and compare the commit timestamp with the time the row becomes visible there. Check pg_stat_replication on the primary and the replay timestamps on the standby to confirm WAL is received promptly but applied only after the delay. The step is done when the test row appears on the standby only after the configured interval has passed, and the standby reports it is still receiving WAL.
Check WAL retention and replication slots on the primary
A delayed standby forces the primary to keep WAL until the standby replays it, so review wal_keep_size, any replication slot the standby uses, and the free space on the WAL volume. Compare the slot's restart_lsn with the current WAL position and estimate how much WAL the delay will hold at your write rate. Ask your team to decide what happens if the disk fills, and set monitoring on slot lag and disk space. The step is done when the slot is listed, its lag is visible, and the alert thresholds are in place.
Archive WAL for point-in-time recovery
Confirm archive_mode and archive_command (or your backup tool's archive hook) are working, so WAL is kept off the primary's disk as well as on the standby. Follow the continuous archiving documentation for the exact settings and the base backup strategy that pairs with them. The step is done when archived WAL segments appear in the archive location and a recent base backup is recorded with its start point.
Rehearse a recovery to a scratch database
Pick a table, simulate an accidental drop in a test environment, and rebuild the lost data from the delayed standby by stopping replay before the bad transaction, using the pause and resume functions in the standby's recovery controls, then copying the needed rows to the primary. Repeat the exercise with point-in-time recovery from the base backup and archived WAL to compare the time and steps each path takes. The step is done when the table's contents match the pre-incident state and the team has written down the steps and the elapsed time.
Document the runbook and schedule retests
Record the delay value, the retention limits, the monitoring thresholds, the recovery steps and the owner of each action in a runbook the on-call team can follow. Ask whether the standby's recovery window still matches data change patterns after schema or traffic changes, and schedule periodic rehearsals. The step is done when the runbook has been reviewed by the people who will use it during an incident and the next rehearsal date is set.
Delayed standby or point-in-time recovery: which one to rely on
Rely on point-in-time recovery as the primary path for human error, and treat a delayed standby as a shortcut for recent mistakes that you can reach quickly. The two overlap, but they are not equivalent. Point-in-time recovery combines a base backup with archived WAL files and can be targeted at a chosen moment, such as the second before a bad DELETE ran. A delayed standby is a live copy of the database held back by recovery_min_apply_delay, so it only covers the window of that delay. Anything older than the delay has already been applied to it, and reading the pre-error data requires an operator to query the standby, export the rows and reapply them to the primary, or promote it in a controlled way.
The practical question is how far back an error is likely to be noticed. If a dropped table or bad update is usually discovered within the delay, the standby can cut recovery time because the data is already running on a server. The cost is on the primary: wal_keep_size or replication slots must retain WAL for the standby, and a long delay raises storage needs and the chance that retained WAL fills the disk. Confirm your retention settings and disk headroom with your team, and monitor them the same way you monitor replication lag. Also confirm how the standby behaves under your application's read traffic, since a delayed standby is generally not suited to serve queries that expect current data.
Keep archived WAL and base backups as the broader safety net, because they cover errors discovered after the delay and failures of the standby itself. Incremental backups taken with pg_basebackup and reconstructed at restore time with pg_combinebackup reduce the backup volume you move, but they add a dependency chain that must be tested during restore planning. Read the continuous archiving documentation before you decide, and run a timed point-in-time restore to a scratch host so the recovery steps and their duration are known before an incident.
Security and operational risks of a delayed copy
A delayed standby is a second full copy of the database, so it carries the same exposure as the primary and adds its own disk and access risks. The cards below cover the controls that keep the copy protected, keep WAL retention from filling the primary, and keep recovery from exposing data to the wrong people.
Match the primary's access controls
A delayed standby holds every row the primary holds, including data that is hours old but still sensitive. Give it the same network restrictions, pg_hba.conf rules, TLS settings and role model as the primary, and keep it out of general reporting or developer access. Review who can connect to it on the same schedule as the primary. Confirm that backup tooling and monitoring agents on the standby are covered by the same review.
Encrypt the standby at rest
Encryption applied to the primary's storage does not automatically cover a standby on a different host or volume. Confirm that the standby's data directory, WAL files and any archived copies use the same disk or filesystem encryption and that the keys are managed separately from the database host. Check that decommissioned volumes and snapshots of the standby are destroyed on the same terms as primary media.
Size disk for WAL retention
The delay makes the primary keep WAL until the standby has replayed it, and a standby that stops receiving WAL or a replication slot that is never consumed can hold WAL on the primary until its disk fills. Set disk alerts on the primary well before the WAL volume is full, and track slot lag and retained WAL as separate metrics. Decide in advance what the team will do if the primary's WAL volume reaches a warning level.
Continuous archiving docsReplay of a bad change
A delay protects against a bad change only if the team notices it before the delay expires. If an error reaches the standby after the window closes, the standby replays it on schedule, so the delayed copy becomes just another copy with the same problem. Set alerts for unexpected large writes or schema changes on the primary, and treat the delay as a window with a deadline, not a permanent safety net.
Limit who can recover data
Recovery from a delayed standby usually means exporting rows or copying tables to a working database, which can expose sensitive data to staff who should not see it. Restrict recovery to a named group, run recovery queries from a restricted host, and log every export and copy. Confirm that recovered data is removed from working environments when the incident closes.
Keep recovery checks in the runbook
A delayed standby that nobody has tested can fail when it is needed, for example if the delay setting was changed or the standby has fallen far behind. Write a recovery procedure that names who may pause replay, how to check replay position and how to stop before the bad change. Rehearse it on a non-production copy and record the time taken so the team knows how long the window actually gives them.
Questions teams ask before building a delayed standby
What does a delayed standby build cost and what drives the effort?
The cost is mostly the engineering time to configure, test and hand over the standby, plus the infrastructure it runs on. Effort rises with the number of primaries, the size of the database, whether the standby already exists as a streaming replica, and how much restore testing your team requires. Retention on the primary is a recurring cost, since WAL must be kept for the length of the delay and storage grows with write volume. DeployOpen does not publish prices, so ask for a written quote built from a fixed scope that lists the primaries covered, the delay window, the storage sizing method, the restore drill and the handover materials. Compare each line with what your team would spend doing the same work internally.
How long does a delayed standby take to build?
The timeline depends on how many primaries are involved, whether a streaming standby already exists, and how quickly your team can approve access, storage and change windows. A standby that is added to a healthy existing replica is usually a smaller task than building the whole replication topology from scratch. Ask the vendor for a timeline in the written scope with named milestones: environment review, configuration in a non-production system, the first delayed restore test, production change and handover. Your own calendar for approvals and maintenance windows will often set the real duration more than the technical work does.
What must our team provide before the work starts?
Expect to provide a server or virtual machine for the standby, storage sized for the delay and the WAL it must hold, network paths between primary and standby, and credentials for the replication role. You also need named owners: a recovery owner who can declare an incident and decide when to promote the delayed standby, and a database administrator who can approve parameter changes on the primary. Access to monitoring and to the backup system is needed so the delay and WAL usage can be watched. Confirm these items against your own environment and change process before the scope is signed.
Can our own team build a delayed standby without a partner?
Yes, if your team already runs PostgreSQL streaming replication and has someone comfortable with recovery settings. The core setting is recovery_min_apply_delay, and the work around it is operational: choosing the delay, sizing WAL retention on the primary, monitoring it, and rehearsing the restore steps. The risk is usually not the configuration but the drill that never happens. A partner is most useful when the team lacks time to rehearse, needs an independent review, or must show evidence to an auditor. Whichever route you choose, write down who runs the recovery and test it before you need it.
Does a delayed standby replace backups or point-in-time recovery?
No. A delayed standby protects against a recent logical mistake, such as a dropped table or a bad update, by letting you stop before the change applies. It does not replace continuous archiving, which combines a base backup with archived WAL so you can restore to a chosen moment. Point-in-time recovery also covers cases a delayed standby cannot, such as a delay window that has already passed, damage to storage on both nodes, or a need to reach an arbitrary time further back. Most teams keep both: backups and archived WAL for long-range recovery, and a delayed standby for fast recovery inside the delay window.
What should we request in a written quote for this work?
Ask for a quote that names the scope in plain terms: the primaries and databases covered, the delay window and how it was chosen, the WAL retention and storage sizing method, the monitoring alerts, and the restore drill with its pass criteria. Also ask what is one-time (design, build, first drill) and what recurs (storage for WAL, monitoring, periodic drills, support). Confirm who performs each step, what you must provide, what is excluded, and how changes after signing are priced. A quote that cannot state these items clearly is not yet a scope you can compare.
Which PostgreSQL versions and settings should our engineers check first?
Start with the version in production, since supported releases are listed in the versioning policy, and confirm that the standby runs a version your team can maintain. Check that the primary keeps enough WAL for the delay by reviewing replication slot settings and disk headroom, and that recovery_min_apply_delay is set on the standby and reported correctly. Verify that the standby is not promoted by accident and that alerts fire when the delay or replay lag drifts. Record the exact commands and steps in a runbook, then rehearse them on a non-production copy.
How WAL flows from the primary to a delayed standby
The diagram starts at the primary, where every committed change is written to WAL. Two copies leave the primary: a streaming connection that delivers WAL to the delayed standby as it is generated, and an archive that keeps WAL files for point-in-time recovery. The standby receives WAL immediately but holds it until the configured recovery_min_apply_delay has passed before replaying it. When a dropped table or bad update is discovered inside that window, the recovery path restores the lost rows from the delayed copy into a scratch database, so production is not overwritten. Check that the delay, WAL retention on the primary and the archive all cover the window you need.
WAL reaches the delayed standby at once but is replayed only after the configured delay.
How DeployOpen scopes and delivers delayed standby work
DeployOpen starts delayed standby work with a written, fixed scope agreed before any server is touched. The scope names the primary and standby hosts, the PostgreSQL major version, the network path between them, the delay the client wants, and the retention the primary must hold. Because the delay only protects data if the client's recovery needs are known, the first working session compares the delay against how quickly the client's teams discover a bad change, how long a restore from backup currently takes, and how much WAL the primary can keep on its disk. Those answers set the value of recovery_min_apply_delay and the size of the WAL retention budget, and they are written into the scope so that the client can check the reasoning later.
The build happens inside the client's own infrastructure, using the client's accounts, data centers or air-gapped network. DeployOpen configures the standby with recovery_min_apply_delay, sets the replication role and its pg_hba.conf entries, checks how WAL is retained on the primary, and sets alerts on standby lag and disk use so that a retention problem is visible before it fills a volume. Each step is documented in a runbook that names the files, settings and commands used, so the client's operators can read it without the DeployOpen team present. Ongoing support, upgrades and periodic retests of the recovery procedure can be added as an optional retainer, agreed in writing separately from the initial scope.
Delivery ends with a recovery rehearsal run by the client's team, with DeployOpen observing and recording the results. The rehearsal covers how to stop replay before a bad change is applied, how to promote or read from the delayed standby, and how the result compares with a restore using point-in-time recovery from base backups and archived WAL. Teams should confirm the expected time to reach the data they need, who has authority to pause or promote, and what is written down for the next incident. The runbook is updated with what the rehearsal showed, and the client decides what to change before the setup is treated as ready.

