﻿# Standby replay delay is not a fresh budget for every query

PostgreSQL standby delay limits WAL replay waiting, not each query's runtime. Earlier conflicts can leave a later query little grace before cancellation.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/postgres-standby-delay-shared-replay-budget/
Language: en

## A new query is canceled surprisingly quickly

A reporting request starts on a standby and is canceled well before the delay configured by the operator. The service interprets this as an early timeout bug. However, the setting may bound delayed WAL replay rather than grant a new full runtime allowance to each query.

The [replication-settings manual](https://www.postgresql.org/docs/18/runtime-config-replication.html) makes this distinction explicit for max_standby_streaming_delay. Earlier conflicting queries can consume the available grace before the new request begins. A per-request stopwatch alone cannot explain that cancellation.

## Identify the conflicting replay requirement

The [hot-standby guide](https://www.postgresql.org/docs/18/hot-standby.html) describes conflicts involving locks, database or tablespace changes and cleanup records. These are not all ordinary CPU contention. The standby must eventually apply changes that already occurred on the primary.

Record the cancellation reason and replay condition before changing a timeout. A query can be computationally cheap yet conflict with required replay. Conversely, a slow query without the relevant conflict is not automatically governed by this cancellation mechanism.

## Start the clock at the right boundary

The delay is evaluated against WAL receipt and application, not independently from the start of every query. If the standby has already waited for earlier work, a later conflicting query may receive considerably less grace until replay catches up.

Preserve WAL receipt, replay progress and conflict events alongside application start times. Do not add the configured delay to each query's start and label an earlier cancellation incorrect. That comparison assumes a contract the setting does not provide.

## Distinguish streaming from archive replay

The documentation provides separate controls for streaming and archive data. The applicable path can change while a lagging standby catches up. Record the active recovery path instead of assuming that a setting with a familiar name controls every stage.

This also matters after reconnection. Newly received data can meet work that has already delayed replay. A service that judges recovery only from successful read-only connections can overlook the remaining freshness debt and the resulting conflict pressure.

## Choose the intended standby role

Longer waiting can protect reporting queries while increasing replay lag and delaying visibility of newer changes. Shorter waiting protects catch-up at the expense of conflicting query continuity. The reference frames this as a role-dependent tradeoff, not a universally optimal timeout.

Feedback can reduce cleanup conflicts while retaining old rows on the primary, but it is not a promise to eliminate every conflict class. [Shared database resources](/journal/pgvector-rag-server/) explains why the primary-side cost belongs in the decision. [Readiness boundaries](/journal/provider-startup-readiness-liveness-separation/) helps distinguish accepting connections from meeting the application's freshness requirement.

## Accept recovery with a conflict history

In a controlled exercise, let an earlier query delay replay and then introduce a later conflicting query. Compare cancellation with the replay timeline rather than inventing a per-query grace guarantee. Acceptance states the standby's role, permitted freshness debt and observed conflict handling. A successful retry can be legitimate after the conflicting WAL is applied, but it is not proof that the original cancellation violated its setting.
