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

PostgreSQL 17 Streaming Read Concurrency and io_combine_limit Invariant

PostgreSQL 17 introduces block-level streaming read infrastructure that aggressively prefetches sequential blocks to maximize I/O throughput. In multi-terabyte analytics and parallel scan workloads, unbounded prefetching collapses kernel page cache and evicts hot shared_buffers blocks, resulting in severe latency spikes. All database pool configurations, analytics runners, and cluster definitions must bound io_combine_limit and session-level read streams to match storage block sizes and controller queue depths.

Prohibited Anti-Pattern: Unbounded Streaming Prefetch and Default io_combine_limit Causing Shared Buffer and Page Cache Eviction

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: PostgreSQL 17 Streaming Read Concurrency and io_combine_limit Invariant - PostgreSQL 17 introduces block-level streaming read infrastructure that aggressively prefetches sequential blocks to maximize I/O throughput. In multi-terabyte analytics and parallel scan workloads, unbounded prefetching collapses kernel page cache and evicts hot shared_buffers blocks, resulting in severe latency spikes. All database pool configurations, analytics runners, and cluster definitions must bound io_combine_limit and session-level read streams to match storage block sizes and controller queue depths.
globs: src/infrastructure/database/**/*.ts, src/database/**/*.ts, src/jobs/**/*.ts, migrations/**/*.sql
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/postgres-17-streaming-io-combine-limit-guardrail"
---

# PostgreSQL 17 Streaming Read Concurrency and io_combine_limit Invariant

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Unbounded Streaming Prefetch and Default io_combine_limit Causing Shared Buffer and Page Cache Eviction

## System Constraints
You are a Principal Software Architect enforcing PostgreSQL 17 Block-Level Streaming I/O Prefetch Optimization. Ensure that all analytical queries, database connection configurations, and migration scripts apply explicit bounds to io_combine_limit and concurrent read streams. Prevent memory pressure and kernel page cache thrashing caused by unchecked sequential scan prefetching in high-throughput data processing contexts.

## Strict Guidelines
- Engineers MUST ALWAYS bound `io_combine_limit` per analytics session or specialized analytics connection pool based on storage stripe and controller queue depth (typically 128kB to 512kB / 16 to 64 blocks on modern NVMe/EBS).
- Engineers MUST NOT run unbounded parallel sequential scans over multi-terabyte tables without setting `effective_io_concurrency` and `io_combine_limit` scoped to session or role boundaries.
- Services MUST isolate analytics workloads that perform full scans into dedicated connection pools that enforce lower prefetch concurrency to protect transactional workloads from shared buffer cache eviction.
- Code SHOULD verify the effective PostgreSQL server version and inspect `pg_stat_io` metrics (`reads`, `extends`, `evictions`) before executing sustained multi-gigabyte or terabyte aggregation pipelines.
- Components NEVER execute raw maintenance operations (e.g., `VACUUM FULL`, `CREATE INDEX`) concurrently with streaming analytics scans without explicitly capping `maintenance_io_concurrency` and sequential prefetch stream limits.

## Bad vs Good Implementations
### Configuring Scoped Streaming I/O Parameters for Analytics Connection Pool

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fails to configure PostgreSQL 17 block-level streaming I/O parameters. Running heavy scans with default cluster settings allows streaming reads to aggressively combine blocks up to controller limits, creating bursty I/O queues and thrashing both kernel page cache and Postgres shared buffers for concurrent OLTP sessions.
```typescript
import { Pool } from 'pg';

// ANTI-PATTERN: Default connection pool executes heavy multi-terabyte analytical queries
// without tuning PostgreSQL 17 streaming I/O prefetch, leading to unbounded block-level reads
// that overwhelm NVMe queues and flush shared_buffers.
export const analyticsPool = new Pool({
  connectionString: process.env.DATABASE_URL,
  max: 20,
  idleTimeoutMillis: 30000,
});

export async function runDatasetScan(query: string) {
  const client = await analyticsPool.connect();
  try {
    return await client.query(query);
  } finally {
    client.release();
  }
}
```

#### Production Standard (Correct)
> **Standard**: Sets PostgreSQL 17 `io_combine_limit` and `effective_io_concurrency` locally for the analytics session, ensuring streaming read prefetching combines blocks up to predictable safe boundaries (256KB) rather than saturating host I/O controllers or evicting OLTP working sets.
```typescript
import { Pool, PoolClient } from 'pg';

// PRODUCTION FIX: Configure dedicated analytics pool that establishes explicit streaming
// I/O limits per session, bounding io_combine_limit and prefetch concurrency to prevent I/O starvation.
const ANALYTICS_IO_COMBINE_LIMIT_BLOCKS = 32; // 32 blocks = 256KB read chunks, matching cloud block storage geometry
const ANALYTICS_EFFECTIVE_IO_CONCURRENCY = 8;

export const analyticsPool = new Pool({
  connectionString: process.env.DATABASE_URL,
  max: 10,
  idleTimeoutMillis: 30000,
});

export async function runDatasetScan<T>(query: string, params: unknown[] = []): Promise<T[]> {
  const client: PoolClient = await analyticsPool.connect();
  try {
    // Bound PostgreSQL 17 streaming I/O chunking and concurrency for this session
    await client.query(`
      SET LOCAL io_combine_limit = '${ANALYTICS_IO_COMBINE_LIMIT_BLOCKS}';
      SET LOCAL effective_io_concurrency = ${ANALYTICS_EFFECTIVE_IO_CONCURRENCY};
      SET LOCAL work_mem = '64MB';
    `);
    
    const result = await client.query(query, params);
    return result.rows as T[];
  } finally {
    // Reset session parameters upon returning connection to pool
    await client.query('DISCARD SEQUENCES; DISCARD TEMP;').catch(() => {});
    client.release();
  }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: PostgreSQL 17 Streaming Read Concurrency and io_combine_limit Invariant

PostgreSQL 17 Streaming Read Concurrency and io_combine_limit Invariant defines an industrial-grade behavioral standard for backend engineering. PostgreSQL 17 introduces block-level streaming read infrastructure that aggressively prefetches sequential blocks to maximize I/O throughput. In multi-terabyte analytics and parallel scan workloads, unbounded prefetching collapses kernel page cache and evicts hot shared_buffers blocks, resulting in severe latency spikes. All database pool configurations, analytics runners, and cluster definitions must bound io_combine_limit and session-level read streams to match storage block sizes and controller queue depths. 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 Streaming Prefetch and Default io_combine_limit Causing Shared Buffer and Page Cache Eviction 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 Streaming Prefetch and Default io_combine_limit Causing Shared Buffer and Page Cache EvictionCritical
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 bound `io_combine_limit` per analytics session or specialized analytics connection pool based on storage stripe and controller queue depth (typically 128kB to 512kB / 16 to 64 blocks on modern NVMe/EBS).

Engineers MUST ALWAYS bound `io_combine_limit` per analytics session or specialized analytics connection pool based on storage stripe and controller queue depth (typically 128kB to 512kB / 16 to 64 blocks on modern NVMe/EBS).

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 NOT run unbounded parallel sequential scans over multi-terabyte tables without setting `effective_io_concurrency` and `io_combine_limit` scoped to session or role boundaries.

Engineers MUST NOT run unbounded parallel sequential scans over multi-terabyte tables without setting `effective_io_concurrency` and `io_combine_limit` scoped to session or role boundaries.

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

Services MUST isolate analytics workloads that perform full scans into dedicated connection pools that enforce lower prefetch concurrency to protect transactional workloads from shared buffer cache eviction.

Services MUST isolate analytics workloads that perform full scans into dedicated connection pools that enforce lower prefetch concurrency to protect transactional workloads from shared buffer cache eviction.

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

Code SHOULD verify the effective PostgreSQL server version and inspect `pg_stat_io` metrics (`reads`, `extends`, `evictions`) before executing sustained multi-gigabyte or terabyte aggregation pipelines.

Code SHOULD verify the effective PostgreSQL server version and inspect `pg_stat_io` metrics (`reads`, `extends`, `evictions`) before executing sustained multi-gigabyte or terabyte aggregation pipelines.

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 maintenance operations (e.g., `VACUUM FULL`, `CREATE INDEX`) concurrently with streaming analytics scans without explicitly capping `maintenance_io_concurrency` and sequential prefetch stream limits.

Components NEVER execute raw maintenance operations (e.g., `VACUUM FULL`, `CREATE INDEX`) concurrently with streaming analytics scans without explicitly capping `maintenance_io_concurrency` and sequential prefetch stream limits.

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 PostgreSQL 17 Streaming Read Concurrency and io_combine_limit Invariant critical for AI coding assistants?

PostgreSQL 17 introduces block-level streaming read infrastructure that aggressively prefetches sequential blocks to maximize I/O throughput. In multi-terabyte analytics and parallel scan workloads, unbounded prefetching collapses kernel page cache and evicts hot shared_buffers blocks, resulting in severe latency spikes. All database pool configurations, analytics runners, and cluster definitions must bound io_combine_limit and session-level read streams to match storage block sizes and controller queue depths. 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 Streaming Prefetch and Default io_combine_limit Causing Shared Buffer and Page Cache Eviction) 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

PostgreSQL