PGX Packs 1,000 Postgres Databases Into One Process at 128 MB

PGX runs thousands of isolated Postgres databases inside a single Rust process, built for throwaway agent sandboxes, CI jobs, and PR previews.

·
·
·
PGX Packs 1,000 Postgres Databases Into One Process at 128 MBPRO
  • PGX runs thousands of isolated Postgres databases inside a single Rust process
  • Warm database creation at 6.2 ms p50, roughly 70 KB memory per idle database
  • 1,000 databases fit in 128 to 155 MB total on a 4 vCPU / 8 GB VPS
  • ZFS copy-on-write branches of a 10 GB template ready in 674 ms, 13.6 MB storage
  • 219 of 231 PostgreSQL regression tests byte-exact; Rails, Django, Prisma, SQLAlchemy pass
  • Beta, AGPL-3.0, not crash-safe or production-ready; built for agents, CI, PR previews

AI agents, CI pipelines, and preview environments frequently need isolated databases for only a few minutes. Teams often provision a separate Postgres instance or container for each environment, adding startup time and memory overhead to every run. PGX is a Rust-based Postgres runtime that creates thousands of isolated databases inside one process and removes them when the work ends.

Shared caches make the density possible

PGX serves each client connection with a thread and isolates databases through names, roles, and resource limits. Databases cloned from the same template reuse identical relation-cache entries, which contain metadata needed to access tables. Each database retains only its own catalog caches and changed state, while autovacuum skips idle databases.

Published benchmarks on a 4 vCPU, 8 GB VPS report the following memory and creation costs:

Test Reported result
1,000 idle PGX databases 128 to 155 MB total
Untouched idle database About 70 KB incremental memory
Previously queried idle database About 128 KB incremental memory
One idle PostgreSQL 18 server 16.6 MB
Database claimed from the warm pool 6.2 ms at p50; 9.4 ms at p99
Cold clone of a 600-file template About 74 ms

The PostgreSQL 18 baseline represents a separate server, matching deployments that assign one instance to each test or preview environment.

ZFS clones pay only for changed blocks

Setting file_copy_method = clone makes PGX create databases with ZFS block clones. A new branch initially shares unchanged blocks with its sealed template, then consumes physical storage as its data diverges. Copy-on-write mode therefore requires ZFS.

Pro article

This story is for Pro members

You've reached the end of the free preview. Upgrade to AlphaSignal Pro to read the full article - and everything else behind the paywall.

Trending
  • No trending articles

Comments

avatar

Next Reads