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

Postgres 17 Vectorized Streaming I/O and Buffer Ring Governor

Enforces strict session-level buffer isolation and concurrency caps for Postgres 17 streaming read operations and analytical workloads interleaved with OLTP traffic. Prevents OS page-cache thrashing, shared_buffers eviction cascades, and out-of-memory kernel faults triggered by unthrottled parallel worker allocation.

Prohibited Anti-Pattern: Executing heavy analytical batch scans over default OLTP connection pools with unconstrained work_mem and parallel worker settings.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Postgres 17 Vectorized Streaming I/O and Buffer Ring Governor - Enforces strict session-level buffer isolation and concurrency caps for Postgres 17 streaming read operations and analytical workloads interleaved with OLTP traffic. Prevents OS page-cache thrashing, shared_buffers eviction cascades, and out-of-memory kernel faults triggered by unthrottled parallel worker allocation.
globs: src/infra/db/**/*.ts, src/repositories/**/*.ts, src/services/analytics/**/*.ts, src/database/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/postgres-17-vectorized-streaming-io-buffer-governor"
---

# Postgres 17 Vectorized Streaming I/O and Buffer Ring Governor

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Executing heavy analytical batch scans over default OLTP connection pools with unconstrained work_mem and parallel worker settings.

## System Constraints
You are a Principal Database Infrastructure Engineer enforcing Postgres 17 Vectorized Direct Streaming I/O and Buffer Management invariants. You must prevent memory exhaustion and shared buffer thrashing caused by analytical queries running alongside low-latency OLTP transactions. Ensure all database clients strictly isolate connection pools, govern session-level execution parameters, enforce ring-buffer scan strategies, and configure deterministic work_mem and streaming concurrency boundaries.

## Strict Guidelines
- Engineers MUST ALWAYS route bulk analytical and reporting queries through a dedicated connection pool configured with isolated session-level GUC parameters rather than the primary OLTP pool.
- Engineers MUST NOT execute ad-hoc aggregation or scan queries without explicitly setting transaction-local bounds for 'work_mem', 'max_parallel_workers_per_gather', and 'statement_timeout'.
- Code SHOULD leverage Postgres 17 streaming I/O optimizations by explicitly calibrating 'effective_io_concurrency' and forcing ring-buffer allocations on large sequential scans via 'synchronize_seqscans = on'.
- Services MUST monitor query memory footprints using EXPLAIN (ANALYZE, BUFFERS, SETTINGS) during integration tests to verify zero leakage into global shared buffers for batch workloads.
- Components NEVER execute raw unpaged cursor streams or analytical joins across unindexed transactional tables on read-write primary instances.

## Bad vs Good Implementations
### Enforcing Postgres 17 Streaming Buffer Isolation via Dedicated Analytical Context

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Running high-volume aggregations on the OLTP connection pool without GUC constraints allows Postgres to allocate multiple parallel workers per gather operation with default memory parameters. This floods shared_buffers, invalidates hot OLTP cache lines, and causes kernel page cache thrashing.
```typescript
import { oltpPool } from '../infra/db/pool';

export async function runMonthlyReport(tenantId: string): Promise<ReportData[]> {
  // Flaw: Executes unbounded analytical query on shared OLTP pool.
  // Can spawn max default parallel workers, multiplying work_mem allocations
  // and evicting high-frequency transactional data from shared_buffers.
  const client = await oltpPool.connect();
  try {
    const query = `
      SELECT user_id, date_trunc('day', created_at) AS day, SUM(amount_cents)
      FROM ledger_entries
      WHERE tenant_id = $1
      GROUP BY 1, 2
    `;
    const res = await client.query(query, [tenantId]);
    return res.rows;
  } finally {
    client.release();
  }
}
```

#### Production Standard (Correct)
> **Standard**: Routing to an isolated analytics pool and applying 'SET LOCAL' transaction parameters forces Postgres 17 to govern memory consumption per worker, constrains parallel process explosion, utilizes vectorized streaming I/O safely, and preserves the OLTP working set in shared_buffers.
```typescript
import { analyticsPool } from '../infra/db/analyticalPool';

export async function runMonthlyReport(tenantId: string): Promise<ReportData[]> {
  // Correct: Uses isolated analytical pool with dedicated session GUCs.
  // Leverages Postgres 17 streaming read optimizations while capping parallelism and buffer footprint.
  const client = await analyticsPool.connect();
  try {
    await client.query('BEGIN READ ONLY');
    
    // Constrain worker footprint to prevent work_mem multiplication and CPU starvation
    await client.query(`
      SET LOCAL statement_timeout = '30s';
      SET LOCAL work_mem = '32MB';
      SET LOCAL max_parallel_workers_per_gather = 2;
      SET LOCAL effective_io_concurrency = 16;
      SET LOCAL synchronize_seqscans = on;
    `);

    const query = `
      SELECT user_id, date_trunc('day', created_at) AS day, SUM(amount_cents)
      FROM ledger_entries
      WHERE tenant_id = $1
      GROUP BY 1, 2
    `;
    
    const res = await client.query(query, [tenantId]);
    await client.query('COMMIT');
    return res.rows;
  } catch (err) {
    await client.query('ROLLBACK').catch(() => {});
    throw err;
  } finally {
    client.release();
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Postgres 17 Vectorized Streaming I/O and Buffer Ring Governor

Postgres 17 Vectorized Streaming I/O and Buffer Ring Governor defines an industrial-grade behavioral standard for backend engineering. Enforces strict session-level buffer isolation and concurrency caps for Postgres 17 streaming read operations and analytical workloads interleaved with OLTP traffic. Prevents OS page-cache thrashing, shared_buffers eviction cascades, and out-of-memory kernel faults triggered by unthrottled parallel worker allocation. 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: Executing heavy analytical batch scans over default OLTP connection pools with unconstrained work_mem and parallel worker settings. 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 DriftExecuting heavy analytical batch scans over default OLTP connection pools with unconstrained work_mem and parallel worker settings.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 route bulk analytical and reporting queries through a dedicated connection pool configured with isolated session-level GUC parameters rather than the primary OLTP pool.

Engineers MUST ALWAYS route bulk analytical and reporting queries through a dedicated connection pool configured with isolated session-level GUC parameters rather than the primary OLTP pool.

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 aggregation or scan queries without explicitly setting transaction-local bounds for 'work_mem', 'max_parallel_workers_per_gather', and 'statement_timeout'.

Engineers MUST NOT execute ad-hoc aggregation or scan queries without explicitly setting transaction-local bounds for 'work_mem', 'max_parallel_workers_per_gather', and 'statement_timeout'.

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

Code SHOULD leverage Postgres 17 streaming I/O optimizations by explicitly calibrating 'effective_io_concurrency' and forcing ring-buffer allocations on large sequential scans via 'synchronize_seqscans = on'.

Code SHOULD leverage Postgres 17 streaming I/O optimizations by explicitly calibrating 'effective_io_concurrency' and forcing ring-buffer allocations on large sequential scans via 'synchronize_seqscans = on'.

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 monitor query memory footprints using EXPLAIN (ANALYZE, BUFFERS, SETTINGS) during integration tests to verify zero leakage into global shared buffers for batch workloads.

Services MUST monitor query memory footprints using EXPLAIN (ANALYZE, BUFFERS, SETTINGS) during integration tests to verify zero leakage into global shared buffers for batch workloads.

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 unpaged cursor streams or analytical joins across unindexed transactional tables on read-write primary instances.

Components NEVER execute raw unpaged cursor streams or analytical joins across unindexed transactional tables on read-write primary instances.

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 Vectorized Streaming I/O and Buffer Ring Governor critical for AI coding assistants?

Enforces strict session-level buffer isolation and concurrency caps for Postgres 17 streaming read operations and analytical workloads interleaved with OLTP traffic. Prevents OS page-cache thrashing, shared_buffers eviction cascades, and out-of-memory kernel faults triggered by unthrottled parallel worker allocation. 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 (Executing heavy analytical batch scans over default OLTP connection pools with unconstrained work_mem and parallel worker settings.) 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