pgRx - PostgreSQL-compatible query engine built on BEAM + Rust

I’ve been working on pgRx: a query engine that uses BEAM lightweight processes instead of PostgreSQL’s fork-per-connection model.

The numbers: 50 idle connections cost PostgreSQL 729MB additional memory. On pgRx it’s 0KB. Hibernated BEAM processes drop to ~400 bytes each.

How it works:

  • Each connection is a GenServer (~2KB active, hibernated to
    ~400 bytes when idle)
  • SQL parsing and execution happens in a Rust NIF via
    pg_query (the same parser PostgreSQL uses)
  • Shared state via RwLock — no per-connection data
    duplication
  • Wire protocol v3 implemented — psql connects without
    changes

What works today: JOINs (all types), subqueries, aggregates, GROUP BY, HAVING, ORDER BY, INSERT/UPDATE/DELETE with RETURNING, prepared statements.

The thesis: PostgreSQL’s process-per-connection model is essentially a worse version of BEAM’s actor model. OpenAI runs 800M ChatGPT users on a single PostgreSQL and has already hit connection storms causing outages. The architecture hasn’t changed since 1986. BEAM was built for exactly this problem at Ericsson - millions of concurrent isolated processes.

GitHub:

Demo site:

Would love to know the parts that have been annoying you, so I can fix them with this iteration.

6 Likes