FORENSIC LEDGER · POSTGRESQL 15–19 · RUST
ZERO DAEMON · ZERO WAL SLOTS · ZERO NEW INFRA

Every row changed. Proven in Postgres.

Auditstream is an open-source audit trail engine in Rust. Adapters attach the actor as a trailing sqlcommenter tag, generated triggers record before and after in auditstream.changes, and the CLI exports on demand with a lossless xid8 cursor.

Postgres
15 – 19
24/7 Daemon
None (0)
TypeScript ESM
Prisma 7 · Drizzle · Node
01 · Trailing sqlcommenter tag (base64url)
NO EXPLICIT TX
1UPDATE invoice
2SET status = $1
3WHERE id = $2
4/*auditstream='eyJ0eXBlIjoidXNlciIsImlkIjoidXNyXzQyIn0'*/
Unpadded base64url can never contain */ or inject SQL. IDs only — no names, emails, or IPs leak into pg_stat_activity.
xact_id 48291044 · public.invoice · UPDATE − open + paid
01 · ATTRIBUTION & CONTRACT

Author in a trailing comment, not a pinned session.

Application code never writes audit rows itself. audit.as() awaits your writes inside AsyncLocalStorage.run() and appends an unpadded base64url sqlcommenter tag — supporting humans, API keys, services, and AI agents acting onBehalfOf a user.

Because comments stay on the statement, standalone Prisma 7 queries need no explicit transaction and never pin connections on RDS Proxy. Malformed payloads never abort your write.

Trailing comment (default)
6,630 tps (−40%) · Pool-safe
set_config (fallback)
5,825 tps (−48%) · Explicit tx
ACTOR PRECEDENCE: 1. set_config → 2. /*auditstream='…'*/ → 3. request.jwt.claims (Supabase) → 4. session_user
1import { PrismaClient } from "@prisma/client";
2import { audit } from "@auditstream/node";
3import { auditstreamPlugin } from "@auditstream/prisma";
4
5const db = new PrismaClient({
6  comments: [auditstreamPlugin()],
7});
8
9await audit.as(
10  {
11    type: "ai_agent",
12    id: "billing-agent",
13    onBehalfOf: { type: "user", id: "usr_42" },
14    tenant: "org_acme",
15  },
16  async () => {
17    await db.invoice.update({
18      where: { id: "inv_901" },
19      data: { status: "paid" },
20    });
21  }
22);
@auditstream/prisma · Prisma 7.1+ SQL comments plugin ESM only · spec 0.1
02 · AUDITSTREAM.CHANGES

The history table is the product.

auditstream.changes is partitioned by month on occurred_at, owned by a dedicated NOLOGIN role, and written exclusively through SECURITY DEFINER triggers. Your application role receives SELECT only — its INSERT, UPDATE, and DELETE tamper attempts are rejected by Postgres itself.

INSERT and DELETE fire once per statement via transition tables (REFERENCING NEW/OLD TABLE); UPDATE stays row-level with WHEN (OLD.* IS DISTINCT FROM NEW.*) so no-op and excluded-column writes record nothing.

xact_id = 48291044
− BEFORE (OLD)jsonb
{
"id": "inv_901",
"amount_cents": 4900,
− "status": "open",
− "paid_at": null
}
+ AFTER (NEW)jsonb
{
"id": "inv_901",
"amount_cents": 4900,
+ "status": "paid",
+ "paid_at": "2026-11-24T04:11Z"
}
actor: ai_agent:billing-agent (onBehalfOf usr_42) SELECT-ONLY FOR APP ROLE
03 · LOSSLESS EXPORT · xid8 WINDOW

Export anywhere, without a 24/7 consumer.

Logical replication needs an always-on consumer — a stopped slot retains WAL and can fill your disk. Auditstream exports pull-based batches on demand using xact_id >= cursor AND xact_id < pg_snapshot_xmin(), acknowledging the cursor only after the sink flushes.

CONCURRENT COMMITS vs. SAFE HORIZON HORIZON: xact_id < 48291042
t0 t1 t2 (Export #1) t3 t4 (Export #2) SAFE EXPORT RANGE xid 48291041 xid 48291042 xid 48291043 xid 48291044 xid 48291045 COMMIT · EXPORTED IN FLIGHT AT t2 — HOLDS xmin (COMMITS LATER AT t3) COMMITTED · WAITS FOR HORIZON invoice='paid' · WAITS IN FLIGHT AT t4 (NEXT xmin) xmin = 48291042
Proven in testing: A cursor on id > last_id lost a row when xid 42 committed after xid 43 and xid 44.
Lossless xid8 window: Run #1 stops cleanly at xact_id < pg_snapshot_xmin() (48291042). Click Run #2 above to watch xid 42, 43, 44 flush in order with stable event_id deduplication.
01 · CONTRACT (spec/)

Versioned & Tested

Normative RFC 2119 spec with language-neutral conformance fixtures in Rust & TS.

02 · CAPTURE (auditstream-pg)

Hybrid Triggers

Statement-level INSERT/DELETE (3× faster bulk), row-level UPDATE, TRUNCATE trigger.

03 · ENGINE (Rust)

Single Static Binary

Hexagonal Cargo workspace (unsafe_code = forbid). Runs on demand or cron.

04 · EXPORT (auditstream-export)

At-Least-Once Sinks

JSON Lines & CSV in v0.1; Webhooks, S3, SIEM, and MCP (rmcp) later.

04 · VERIFIED EVIDENCE · 2026-11-24

Measured on Postgres 15–19. Honest limits.

Every claim below was benchmarked directly on PostgreSQL 16.15 (pgbench, 4 clients) and verified across local Postgres 15–19, PgBouncer 1.26, Neon (PG 18.7), and Supabase Supavisor (PG 17.12). Read the full Evidence log →

Operational requirement Auditstream · Comment (default) Auditstream · set_config (fallback) Logical Replication (pgoutput)
Database setup Any PG 15–19 (free tiers too) Any PG 15–19 wal_level=logical · RDS reboot
Before & after values OLD / NEW in trigger OLD / NEW in trigger REPLICA IDENTITY FULL per table
24/7 consumer daemon None — export on demand None — export on demand Required (slot can fill disk)
Connection poolers PgBouncer · Neon · Supavisor Pins session in RDS Proxy Needs explicit tx per write
Worst-case single-row UPDATE 6,630 tps (−40% vs 11,105) 5,825 tps (−48% vs 11,105) Lower write cost · higher WAL
Known limits (honest) No Aurora DSQL · RDS Proxy untested Use under Prisma Accelerate Deferred behind EventSource
PostgreSQL 16.15 · pgbench (4 clients) · Real measured throughput

Single-row updates are the worst case; bulk inserts run 3× faster with statement-level transition tables (155–180 ms vs 541–550 ms for 10,000 rows).

Single-row INSERT · statement-level trigger 7,906 tps (vs 9,572 base)
Single-row UPDATE · SQL comment 6,630 tps (−40%)
Single-row UPDATE · set_config fallback 5,825 tps (−48%)
Concurrency & Tamper Proof

18,748 pooled writes. Zero leaked actors.

Tested through PgBouncer 1.26, Neon pooler (HTTP & WebSocket), and Supabase Supavisor with more clients than server connections: 9,436 set_config rows and 9,312 actor-less rows interleaved with zero crossover.

PG 15.20 · 16.15 · 17.12 · 18.7 · 19.0 — IDENTICAL 17/17 SUITE
10,000-row INSERT
155–180 ms (3× faster)
Prisma 7.10 & Drizzle
80 concurrent · 0 wrong
App Role Tamper Tests
INSERT / UPDATE / DELETE denied
Cloud Poolers Proven
Neon · Supabase · PgBouncer
05 · ROADMAP · 59 ISSUES · 5 WAVES

Built in five waves, behind EventSource.

The contract in spec/ gates both repositories. v0.1 ships triggers, auditstream.changes, JSONL/CSV export, and TypeScript adapters; S3/Webhooks/SIEM, MCP (rmcp), and optional WAL replication via pg_logical_emit_message follow behind the same port traits.

W1
ACTIVE · CONTRACT

Spec v0.1 & CI

Normative spec/, JSON schemas, conformance fixtures, Cargo & pnpm foundations.

W2
WAVE 2 · CORE

Core & @auditstream/node

Domain types, port traits, base64url transport codec passing shared fixtures in Rust & TS.

W3
WAVE 3 · CAPTURE

Triggers, Export & ORMs

auditstream-pg, JSONL/CSV sinks, Prisma 7 plugin, Drizzle 0.45 & 1.x wrappers.

W4
WAVE 4 · CLI

CLI & App Examples

init, verify, history, export + Next.js & Hono example apps.

W5
WAVE 5 · RELEASE

Dist, Docs & Beyond

npm, Homebrew, shell installer, ghcr.io. Later: S3, SIEM, MCP & WAL EventSource.

  1. 01

    Generate migration & triggers

    Writes the monthly-partitioned auditstream.changes table and triggers for Prisma, Drizzle, or plain SQL.

    terminal · auditstream CLI
    $auditstream init --format prisma --tables invoice,users
     # wrote partitioned auditstream.changes + triggers
     # statement-level INSERT/DELETE · row-level UPDATE
  2. 02

    Install the TypeScript adapter

    ESM-only packages for Node 22.12+, Bun, Deno, and Cloudflare Workers.

    terminal · auditstream-js
    $pnpm add @auditstream/node @auditstream/prisma
  3. 03

    Inspect diffs or export on demand

    Query history from the CLI or export JSON Lines / CSV using the commit-safe xid8 cursor.

    terminal · history & export
    $auditstream history --table invoice --limit 10
     auditstream export --format jsonl --out audit.jsonl
     # xact_id window exported · acked after sink flush