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

PostgreSQL 17 Asynchronous Direct I/O and Vectorized Buffer Pinning Standard

Enforces architectural patterns for PostgreSQL 17 asynchronous streaming read pipelines and direct I/O orchestration to eradicate Linux kernel page-cache double-buffering and tail latency spikes. Ensures analytical queries, sequential scans, and bulk ingestion operations leverage vectorized multi-block buffer pinning and bypass OS buffer layers safely.

Prohibited Anti-Pattern: Unbuffered synchronous table scans thrashing OS page cache and inducing severe double-buffering lock contention

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: PostgreSQL 17 Asynchronous Direct I/O and Vectorized Buffer Pinning Standard - Enforces architectural patterns for PostgreSQL 17 asynchronous streaming read pipelines and direct I/O orchestration to eradicate Linux kernel page-cache double-buffering and tail latency spikes. Ensures analytical queries, sequential scans, and bulk ingestion operations leverage vectorized multi-block buffer pinning and bypass OS buffer layers safely.
globs: src/db/**/*.ts, src/repositories/**/*.ts, src/services/**/*.ts, migrations/**/*.sql
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/postgres-17-async-direct-io-buffer-pinning-standard"
---

# PostgreSQL 17 Asynchronous Direct I/O and Vectorized Buffer Pinning Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Unbuffered synchronous table scans thrashing OS page cache and inducing severe double-buffering lock contention

## System Constraints
You are a Principal Database Architect and Infrastructure Guardrail Author enforcing the PostgreSQL 17 Asynchronous Direct I/O and Vectorized Buffer Pinning Standard. Your mandate is to prevent OS kernel page-cache pollution, eliminate p99 tail latency amplification, and ensure high-throughput bulk pipelines exploit PG17 streaming read primitives, non-blocking AIO work queues, and block-aligned vectorization.

## Strict Guidelines
- Engineers MUST configure session-level and instance-level I/O concurrency to leverage PostgreSQL 17 streaming read primitives (`io_combine_limit >= 32` and `maintenance_io_workers >= 4`) for batch and analytical workloads.
- Engineers MUST NOT execute unconstrained bulk sequential scans or large COPY operations through standard application connection pools without explicit buffer ring constraints or direct streaming cursor configurations.
- Data ingestion services MUST chunk data into exact block-aligned multiples (e.g., 8 KiB page boundaries, typically 64 KiB or 128 KiB batches) to maximize direct I/O hardware alignment and eliminate partial-page CPU thrashing.
- Services performing analytical read-heavy operations MUST allocate dedicated connection profiles configured with `synchronous_commit = off` (for staging temp writes) and verify vector buffer pinning via `EXPLAIN (ANALYZE, BUFFERS, IO)` telemetry.
- Components NEVER issue unbounded parallel queries that exhaust PG17 AIO queue depths, preventing asynchronous worker starvation and kernel io_uring/libaio submission contention.

## Bad vs Good Implementations
### Configuring Vectorized Streaming Scans vs. Naive Sequential Queries

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Executes an unbounded high-throughput query using default single-block synchronous access semantics. This causes double-buffering between PostgreSQL shared buffers and the OS page cache, generating excessive TLB shootdowns and p99 latency spikes across concurrent transactions.
```typescript
import { Pool } from 'pg';

export async function exportAnalyticalDataset(pool: Pool, customerId: string) {
  const client = await pool.connect();
  try {
    // ANTI-PATTERN: Standard query on high-volume table bypasses PG17 streaming parameters,
    // defaults to synchronous single-page I/O, floods OS page cache, and causes double-buffering.
    const result = await client.query(
      'SELECT id, payload, created_at FROM event_telemetry WHERE customer_id = $1',
      [customerId]
    );
    return result.rows;
  } finally {
    client.release();
  }
}
```

#### Production Standard (Correct)
> **Standard**: Leverages PostgreSQL 17's vectorized streaming pipeline by setting `io_combine_limit` and employing cursor streams with page-aligned chunk sizes. This ensures requests are collapsed into contiguous asynchronous direct I/O requests, bypassing kernel page cache locks and eliminating tail latency.
```typescript
import { Pool } from 'pg';
import QueryStream from 'pg-query-stream';

export async function exportAnalyticalDataset(pool: Pool, customerId: string): Promise<NodeJS.ReadableStream> {
  const client = await pool.connect();
  try {
    // Standardized for PG17: Set session-level vectorization and direct read parameters.
    // io_combine_limit instructs PG17 streaming read engine to vectorize multi-block requests.
    await client.query('SET LOCAL io_combine_limit = 64;');
    await client.query('SET LOCAL work_mem = "128MB";');

    const queryText = `
      SELECT id, payload, created_at 
      FROM event_telemetry 
      WHERE customer_id = $1
    `;
    
    // Stream using block-aligned batch sizing (aligned with 8KiB * 16 = 128KiB buffer windows)
    const stream = client.query(new QueryStream(queryText, [customerId], { batchSize: 2048 }));
    
    stream.on('end', () => {
      client.release();
    });
    stream.on('error', () => {
      client.release();
    });

    return stream;
  } catch (error) {
    client.release();
    throw error;
  }
}
```

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 Asynchronous Direct I/O and Vectorized Buffer Pinning Standard

PostgreSQL 17 Asynchronous Direct I/O and Vectorized Buffer Pinning Standard defines an industrial-grade behavioral standard for backend engineering. Enforces architectural patterns for PostgreSQL 17 asynchronous streaming read pipelines and direct I/O orchestration to eradicate Linux kernel page-cache double-buffering and tail latency spikes. Ensures analytical queries, sequential scans, and bulk ingestion operations leverage vectorized multi-block buffer pinning and bypass OS buffer layers safely. 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: Unbuffered synchronous table scans thrashing OS page cache and inducing severe double-buffering lock contention 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 DriftUnbuffered synchronous table scans thrashing OS page cache and inducing severe double-buffering lock contentionCritical
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 configure session-level and instance-level I/O concurrency to leverage PostgreSQL 17 streaming read primitives (`io_combine_limit >= 32` and `maintenance_io_workers >= 4`) for batch and analytical workloads.

Engineers MUST configure session-level and instance-level I/O concurrency to leverage PostgreSQL 17 streaming read primitives (`io_combine_limit >= 32` and `maintenance_io_workers >= 4`) for batch and analytical 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.
2

Engineers MUST NOT execute unconstrained bulk sequential scans or large COPY operations through standard application connection pools without explicit buffer ring constraints or direct streaming cursor configurations.

Engineers MUST NOT execute unconstrained bulk sequential scans or large COPY operations through standard application connection pools without explicit buffer ring constraints or direct streaming cursor 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.
3

Data ingestion services MUST chunk data into exact block-aligned multiples (e.g., 8 KiB page boundaries, typically 64 KiB or 128 KiB batches) to maximize direct I/O hardware alignment and eliminate partial-page CPU thrashing.

Data ingestion services MUST chunk data into exact block-aligned multiples (e.g., 8 KiB page boundaries, typically 64 KiB or 128 KiB batches) to maximize direct I/O hardware alignment and eliminate partial-page CPU thrashing.

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 performing analytical read-heavy operations MUST allocate dedicated connection profiles configured with `synchronous_commit = off` (for staging temp writes) and verify vector buffer pinning via `EXPLAIN (ANALYZE, BUFFERS, IO)` telemetry.

Services performing analytical read-heavy operations MUST allocate dedicated connection profiles configured with `synchronous_commit = off` (for staging temp writes) and verify vector buffer pinning via `EXPLAIN (ANALYZE, BUFFERS, IO)` telemetry.

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 issue unbounded parallel queries that exhaust PG17 AIO queue depths, preventing asynchronous worker starvation and kernel io_uring/libaio submission contention.

Components NEVER issue unbounded parallel queries that exhaust PG17 AIO queue depths, preventing asynchronous worker starvation and kernel io_uring/libaio submission contention.

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 Asynchronous Direct I/O and Vectorized Buffer Pinning Standard critical for AI coding assistants?

Enforces architectural patterns for PostgreSQL 17 asynchronous streaming read pipelines and direct I/O orchestration to eradicate Linux kernel page-cache double-buffering and tail latency spikes. Ensures analytical queries, sequential scans, and bulk ingestion operations leverage vectorized multi-block buffer pinning and bypass OS buffer layers safely. 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 (Unbuffered synchronous table scans thrashing OS page cache and inducing severe double-buffering lock contention) 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