This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: postgres-17-streaming-io-concurrency-limiter

Postgres 17 Asynchronous Streaming I/O Concurrency Limiter Guardrail

Postgres 17 introduces streaming asynchronous read prefetching for sequential and bitmap heap scans. Unthrottled parallel execution of streaming queries can exhaust kernel page-cache buffers and saturate OS I/O pipelines, starving latency-sensitive transaction backends. Services must enforce concurrency limiters and query-scoped GUC tuning before dispatching streaming-intensive operations.

Prohibited Anti-Pattern: Unbounded parallel scan dispatches triggering PG17 streaming I/O storms and worker starvation.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Postgres 17 Asynchronous Streaming I/O Concurrency Limiter Guardrail - Postgres 17 introduces streaming asynchronous read prefetching for sequential and bitmap heap scans. Unthrottled parallel execution of streaming queries can exhaust kernel page-cache buffers and saturate OS I/O pipelines, starving latency-sensitive transaction backends. Services must enforce concurrency limiters and query-scoped GUC tuning before dispatching streaming-intensive operations.
globs: src/**/*.ts, src/db/**/*.ts, src/repositories/**/*.ts, src/services/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/postgres-17-streaming-io-concurrency-limiter"
---

# Postgres 17 Asynchronous Streaming I/O Concurrency Limiter Guardrail

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Unbounded parallel scan dispatches triggering PG17 streaming I/O storms and worker starvation.

## System Constraints
You are a Principal Software Architect enforcing production reliability under PostgreSQL 17's Asynchronous Streaming I/O subsystem. Under PG17, sequential scans, bitmap heap scans, and vacuum operations leverage streaming I/O to asynchronously prefetch blocks ahead of execution workers. When unthrottled, concurrent parallel scans trigger severe kernel page-cache thrashing, direct worker memory exhaustion, and I/O starvation for transactional OLTP queries. Mandate application-layer concurrency limits, transaction-scoped GUC constraints (io_combine_limit, effective_io_concurrency, max_parallel_workers_per_gather), and dedicated connection isolation for large scan workloads.

## Strict Guidelines
- Engineers MUST ALWAYS isolate large sequential or analytical scans behind an application-level concurrency limiter or semaphore (e.g., p-limit or worker pool) to cap simultaneous streaming read operations.
- Engineers MUST set transaction-local I/O limits using `SET LOCAL effective_io_concurrency` and `SET LOCAL io_combine_limit` when dispatching known heavy table scans or batch export queries in Postgres 17.
- Engineers MUST NOT execute bulk data scans using unmetered fan-out constructs like `Promise.all` across partitions or large tenant tables.
- Services MUST route streaming-heavy batch queries to a dedicated, read-replica connection pool with capped pool sizes and restricted `max_parallel_workers_per_gather` settings.
- Components NEVER execute raw unbounded full-table scans concurrently with critical low-latency OLTP transactions on the same Postgres primary instance.

## Bad vs Good Implementations
### Mitigating PG17 Streaming I/O Overload via Transactional GUCs and Concurrency Limiting

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using unmetered Promise.all to trigger concurrent sequential scans in Postgres 17 allows streaming read prefetchers across parallel workers to saturate the kernel block layer and blow out the OS page cache, starving transactional operations.
```typescript
import { Pool } from 'pg';

export async function runPartitionScans(pool: Pool, partitionKeys: string[]): Promise<void> {
  // ANTI-PATTERN: Uncapped parallel fan-out dispatches simultaneous streaming sequential scans.
  // In Postgres 17, each parallel worker initiates aggressive asynchronous prefetching,
  // thrashing shared buffers, evicting the OS page cache, and starving OLTP worker backends.
  await Promise.all(
    partitionKeys.map(async (key) => {
      const client = await pool.connect();
      try {
        await client.query(
          'SELECT aggregate_metrics(data) FROM telemetry_events WHERE partition_key = $1',
          [key]
        );
      } finally {
        client.release();
      }
    })
  );
}
```

#### Production Standard (Correct)
> **Standard**: Enforces a concurrency throttle (pLimit) and wraps each execution in a read-only transaction with constrained local GUCs (effective_io_concurrency, io_combine_limit, max_parallel_workers_per_gather) to prevent PG17 AIO prefetch saturation.
```typescript
import { Pool, PoolClient } from 'pg';
import pLimit from 'p-limit';

// Cap concurrent streaming scans to prevent kernel page-cache thrashing
const SCAN_CONCURRENCY_LIMIT = 3;
const scanLimiter = pLimit(SCAN_CONCURRENCY_LIMIT);

export async function runPartitionScans(pool: Pool, partitionKeys: string[]): Promise<void> {
  await Promise.all(
    partitionKeys.map((key) =>
      scanLimiter(async () => {
        const client: PoolClient = await pool.connect();
        try {
          await client.query('BEGIN READ ONLY');

          // Tame Postgres 17 streaming I/O prefetch bounds for analytical scans
          await client.query('SET LOCAL effective_io_concurrency = 2');
          await client.query('SET LOCAL io_combine_limit = 16');
          await client.query('SET LOCAL max_parallel_workers_per_gather = 2');

          await client.query(
            'SELECT aggregate_metrics(data) FROM telemetry_events WHERE partition_key = $1',
            [key]
          );

          await client.query('COMMIT');
        } catch (error) {
          await client.query('ROLLBACK');
          throw error;
        } finally {
          client.release();
        }
      })
    )
  );
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Postgres 17 Asynchronous Streaming I/O Concurrency Limiter Guardrail

Postgres 17 Asynchronous Streaming I/O Concurrency Limiter Guardrail defines an industrial-grade behavioral standard for backend engineering. Postgres 17 introduces streaming asynchronous read prefetching for sequential and bitmap heap scans. Unthrottled parallel execution of streaming queries can exhaust kernel page-cache buffers and saturate OS I/O pipelines, starving latency-sensitive transaction backends. Services must enforce concurrency limiters and query-scoped GUC tuning before dispatching streaming-intensive operations. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unbounded parallel scan dispatches triggering PG17 streaming I/O storms and worker starvation. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnbounded parallel scan dispatches triggering PG17 streaming I/O storms and worker starvation.Critical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS isolate large sequential or analytical scans behind an application-level concurrency limiter or semaphore (e.g., p-limit or worker pool) to cap simultaneous streaming read operations.

Engineers MUST ALWAYS isolate large sequential or analytical scans behind an application-level concurrency limiter or semaphore (e.g., p-limit or worker pool) to cap simultaneous streaming read operations.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST set transaction-local I/O limits using `SET LOCAL effective_io_concurrency` and `SET LOCAL io_combine_limit` when dispatching known heavy table scans or batch export queries in Postgres 17.

Engineers MUST set transaction-local I/O limits using `SET LOCAL effective_io_concurrency` and `SET LOCAL io_combine_limit` when dispatching known heavy table scans or batch export queries in Postgres 17.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT execute bulk data scans using unmetered fan-out constructs like `Promise.all` across partitions or large tenant tables.

Engineers MUST NOT execute bulk data scans using unmetered fan-out constructs like `Promise.all` across partitions or large tenant tables.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST route streaming-heavy batch queries to a dedicated, read-replica connection pool with capped pool sizes and restricted `max_parallel_workers_per_gather` settings.

Services MUST route streaming-heavy batch queries to a dedicated, read-replica connection pool with capped pool sizes and restricted `max_parallel_workers_per_gather` settings.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER execute raw unbounded full-table scans concurrently with critical low-latency OLTP transactions on the same Postgres primary instance.

Components NEVER execute raw unbounded full-table scans concurrently with critical low-latency OLTP transactions on the same Postgres primary instance.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Postgres 17 Asynchronous Streaming I/O Concurrency Limiter Guardrail critical for AI coding assistants?

Postgres 17 introduces streaming asynchronous read prefetching for sequential and bitmap heap scans. Unthrottled parallel execution of streaming queries can exhaust kernel page-cache buffers and saturate OS I/O pipelines, starving latency-sensitive transaction backends. Services must enforce concurrency limiters and query-scoped GUC tuning before dispatching streaming-intensive operations. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unbounded parallel scan dispatches triggering PG17 streaming I/O storms and worker starvation.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Postgres