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

Postgres 17 Streaming I/O Direct Buffer Quota & Prefetch Bounding Standard

Enforces strict bounds on PostgreSQL 17 asynchronous streaming I/O buffer allocations and prefetching limits across pooled analytical connections. Unbounded direct block prefetching exhausts Linux page cache space and shared buffer ring allocations, evicting hot transactional pages and inducing severe tail latency spikes in OLTP paths.

Prohibited Anti-Pattern: Unbounded AIO Prefetching and Global Shared Buffer Saturation During Analytical Scans

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Postgres 17 Streaming I/O Direct Buffer Quota & Prefetch Bounding Standard - Enforces strict bounds on PostgreSQL 17 asynchronous streaming I/O buffer allocations and prefetching limits across pooled analytical connections. Unbounded direct block prefetching exhausts Linux page cache space and shared buffer ring allocations, evicting hot transactional pages and inducing severe tail latency spikes in OLTP paths.
globs: src/database/**/*.{ts,js,sql}, src/infra/**/*.{ts,js,tf}, src/config/**/*.{ts,js}, migrations/**/*.sql
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/postgres-17-streaming-io-direct-buffer-quota-standard"
---

# Postgres 17 Streaming I/O Direct Buffer Quota & Prefetch Bounding Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Unbounded AIO Prefetching and Global Shared Buffer Saturation During Analytical Scans

## System Constraints
You are a Principal Database Infrastructure Engineer enforcing the Postgres 17 Streaming I/O Direct Buffer Quota Standard. PostgreSQL 17 introduces generalized streaming I/O infrastructure allowing asynchronous concurrent prefetching for sequential scans, bitmap heap scans, and vacuum operations. You must mandate strict session-level limits on prefetch depth (`io_combine_limit`, `effective_io_concurrency`, and maintenance workers) and ensure backend connections segregating OLAP/batch queries apply localized buffer quotas and temporary direct table spaces to prevent dirtying shared buffers or blowing out host OS page cache pages critical to transactional throughput.

## Strict Guidelines
- Engineers MUST ALWAYS isolate analytical workloads into dedicated connection roles configured with constrained `effective_io_concurrency` and capped `maintenance_io_concurrency`.
- Engineers MUST NOT execute ad-hoc heavy analytical scans against transactional connection pools without explicitly setting `SET LOCAL synchronous_commit TO off` or scoping session-level buffer limits where supported.
- Engineers MUST configure session-level read streams to respect `io_combine_limit` sizing compatible with OS block limits to prevent sequential scans from choking the system I/O queue.
- Database access layers MUST enforce connection-level execution limits using dedicated connection pools with distinct user roles (`reporting_user` vs `oltp_user`) that declare bounded streaming I/O configurations.
- Engineers MUST NEVER configure `shared_buffers` beyond 40% of system RAM when streaming I/O is enabled, ensuring adequate unpinned host page cache is preserved for kernel-level read-ahead coordination.

## Bad vs Good Implementations
### Configuring Analytical Connection Pool with PostgreSQL 17 Streaming I/O Quota Guards

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Executing massive analytical queries on default connection pools causes PostgreSQL 17's streaming I/O to maximize asynchronous block prefetching via OS system calls. This floods I/O queues and evicts critical OLTP indexes and tuples from the shared buffers and host page cache.
```typescript
import { Pool } from 'pg';

// ANTI-PATTERN: Analytical query using default OLTP connection settings.
// Default PG17 streaming I/O permits high prefetch concurrency, which causes heavy
// analytical sequential scans to evict hot OLTP pages from shared buffers and OS page cache.
export const reportPool = new Pool({
  connectionString: process.env.DATABASE_URL,
  max: 20,
});

export async function runMonthlyAggregation(tenantId: string): Promise<any[]> {
  const client = await reportPool.connect();
  try {
    // Scans gigabytes of unindexed rows; streaming I/O executes unconstrained asynchronous block reads
    const result = await client.query(
      'SELECT date_trunc(\'day\', created_at), sum(amount) FROM ledger_entries WHERE tenant_id = $1 GROUP BY 1',
      [tenantId]
    );
    return result.rows;
  } finally {
    client.release();
  }
}
```

#### Production Standard (Correct)
> **Standard**: The bounded pattern uses a dedicated read-only analytics pool with constrained worker allocation. It issues session-scoped guardrails (`effective_io_concurrency = 2`) inside a read-only transaction, ensuring PostgreSQL 17's streaming engine throttles asynchronous prefetching and bounds memory pressure, keeping the Linux page cache stable for transactional operations.
```typescript
import { Pool, PoolClient } from 'pg';

// PRODUCTION FIX: Analytical pool with bounded prefetch and strict I/O quotas
export const analyticsPool = new Pool({
  connectionString: process.env.ANALYTICS_DATABASE_URL,
  max: 5,
  statement_timeout: 30000,
});

export async function runMonthlyAggregation(tenantId: string): Promise<any[]> {
  const client: PoolClient = await analyticsPool.connect();
  try {
    await client.query('BEGIN READ ONLY');
    // Bound asynchronous prefetching and direct streaming I/O for this analytical session
    // Prevents aggressive block prefetching from saturating storage queue and evicting OLTP cache
    await client.query('SET LOCAL effective_io_concurrency = 2');
    await client.query('SET LOCAL work_mem = \'64MB\'');
    
    const result = await client.query(
      `SELECT date_trunc('day', created_at) AS day, sum(amount) AS total
       FROM ledger_entries
       WHERE tenant_id = $1
       GROUP BY 1`,
      [tenantId]
    );
    
    await client.query('COMMIT');
    return result.rows;
  } catch (err) {
    await client.query('ROLLBACK');
    throw err;
  } finally {
    client.release();
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Postgres 17 Streaming I/O Direct Buffer Quota & Prefetch Bounding Standard

Postgres 17 Streaming I/O Direct Buffer Quota & Prefetch Bounding Standard defines an industrial-grade behavioral standard for backend engineering. Enforces strict bounds on PostgreSQL 17 asynchronous streaming I/O buffer allocations and prefetching limits across pooled analytical connections. Unbounded direct block prefetching exhausts Linux page cache space and shared buffer ring allocations, evicting hot transactional pages and inducing severe tail latency spikes in OLTP paths. 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 AIO Prefetching and Global Shared Buffer Saturation During Analytical Scans 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 AIO Prefetching and Global Shared Buffer Saturation During Analytical ScansCritical
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 analytical workloads into dedicated connection roles configured with constrained `effective_io_concurrency` and capped `maintenance_io_concurrency`.

Engineers MUST ALWAYS isolate analytical workloads into dedicated connection roles configured with constrained `effective_io_concurrency` and capped `maintenance_io_concurrency`.

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 execute ad-hoc heavy analytical scans against transactional connection pools without explicitly setting `SET LOCAL synchronous_commit TO off` or scoping session-level buffer limits where supported.

Engineers MUST NOT execute ad-hoc heavy analytical scans against transactional connection pools without explicitly setting `SET LOCAL synchronous_commit TO off` or scoping session-level buffer limits where supported.

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 configure session-level read streams to respect `io_combine_limit` sizing compatible with OS block limits to prevent sequential scans from choking the system I/O queue.

Engineers MUST configure session-level read streams to respect `io_combine_limit` sizing compatible with OS block limits to prevent sequential scans from choking the system I/O queue.

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

Database access layers MUST enforce connection-level execution limits using dedicated connection pools with distinct user roles (`reporting_user` vs `oltp_user`) that declare bounded streaming I/O configurations.

Database access layers MUST enforce connection-level execution limits using dedicated connection pools with distinct user roles (`reporting_user` vs `oltp_user`) that declare bounded streaming I/O configurations.

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

Engineers MUST NEVER configure `shared_buffers` beyond 40% of system RAM when streaming I/O is enabled, ensuring adequate unpinned host page cache is preserved for kernel-level read-ahead coordination.

Engineers MUST NEVER configure `shared_buffers` beyond 40% of system RAM when streaming I/O is enabled, ensuring adequate unpinned host page cache is preserved for kernel-level read-ahead coordination.

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 Streaming I/O Direct Buffer Quota & Prefetch Bounding Standard critical for AI coding assistants?

Enforces strict bounds on PostgreSQL 17 asynchronous streaming I/O buffer allocations and prefetching limits across pooled analytical connections. Unbounded direct block prefetching exhausts Linux page cache space and shared buffer ring allocations, evicting hot transactional pages and inducing severe tail latency spikes in OLTP paths. 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 AIO Prefetching and Global Shared Buffer Saturation During Analytical Scans) 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