Minipg Puts Real PostgreSQL Behind a Single Executable
PostgreSQL normally arrives with an installation, a running server, and a data directory whose lifecycle you manage. Minipg changes the first two parts of that experience. You download one executable, point it at a directory, and get a psql session connected to a real PostgreSQL cluster. When a command needs a server, minipg starts one. After the work is done and connections have gone away, it stops.
The word “single” describes the distributed program, not the database on disk. An app.pgdb directory holds the persistent cluster, its settings, its generated credentials, and the PostgreSQL version it expects. Underneath the convenient command line is PostgreSQL 18 from the official Alpine image, run through a young virtual-machine runtime called hyper9. The result is a deliberately different way to package PostgreSQL, with useful applications and substantial limits.
A directory becomes the unit of ownership
The shortest path from an empty working directory to SQL is minipg app.pgdb. If the path does not exist, minipg creates it and initializes a cluster. It then opens psql on a database named app. The same command with a SQL string runs a statement without entering the interactive shell:
minipg app.pgdb
minipg app.pgdb "create table notes (id serial primary key, body text)"
minipg app.pgdb "insert into notes (body) values ('hello')"
minipg app.pgdb "select * from notes"
The directory is ordinary filesystem content, not an opaque database image. Its pgdata/ subdirectory contains PostgreSQL’s data files. minipg.toml records the layout format, major version, image digest, default database, preferred port, superuser name, and generated password. A .lock keeps a second minipg server from opening the same cluster simultaneously. The configuration file is created with mode 0600 because the password lives there.
.pgdb directory owns its cluster state.This layout makes it natural to keep separate databases next to separate projects. The directory can be moved or copied after the server stops. A live copy is not necessarily consistent: PostgreSQL’s own file-level backup rules require a stopped server or a consistent snapshot. For a running cluster, minipg exposes pg_dump through minipg dump app.pgdb > app.sql and restores a dump with minipg restore copy.pgdb app.sql. A dump of the default database is different from copying the entire cluster, which may contain other databases and roles.
How one executable runs a real server
Minipg does not reimplement PostgreSQL’s SQL engine. Its build embeds a trimmed root filesystem from Docker Hub’s postgres:18-alpine image, including the Alpine PostgreSQL binaries. On first use, it unpacks that root to a cache. The default major works offline because its root travels inside the executable; a different major can be fetched and cached later. The .pgdb records the version and image identity it needs so a later invocation can locate the matching root.
The embedded binaries are Linux programs. Hyper9, used as a Zig library, gives them a Linux-facing environment on host hypervisors, with its Plan 9 kernel handling their system calls. There is no Docker daemon and no guest Linux kernel to boot. The server process holds one hyper9 machine with the unpacked image as its Linux root and the .pgdb as writable working storage. On first start, the image’s docker-entrypoint.sh initializes the database. Command-line tools such as psql and pg_dump use separate, short-lived machines over the same root and connect to the server.
On Linux x86-64, hyper9 can use KVM or a native backend that needs no /dev/kvm; that native path is what the project has measured. Linux arm64 uses KVM. Apple Silicon builds target Hypervisor.framework, while Windows x86-64 builds use Windows Hypervisor Platform. The project’s platform table distinguishes builds from systems it has actually run: at publication, it reports testing for Linux x86-64’s native backend and Windows x86-64, while Linux arm64 and macOS builds have not been run by the project.
A server that appears when needed
The command that opens a shell does not keep the database server inside that shell process. If a server is already running for the directory, minipg reuses it. Otherwise, it starts a background server, waits for readiness, and connects. A lock ensures only one server owns a .pgdb at a time. The default idle period is 60 seconds after clients disconnect, so a second command usually reaches a warm server. minipg serve app.pgdb keeps a server in the foreground when that lifecycle is preferable; stop, status, and logs provide direct control and visibility.
Applications use the ordinary PostgreSQL protocol over loopback. minipg url app.pgdb prints a connection URL with the current port and generated password. minipg run app.pgdb -- npm start starts a host command with DATABASE_URL and PostgreSQL environment variables set, and holds the server open until the command exits. The configured port is preferred rather than guaranteed: if it is occupied, minipg chooses another and reports the live port in the URL. Connections authenticate with SCRAM, including on loopback. The password-bearing URL should therefore be handled like any other database secret.
This is especially convenient in tests. A CI job can initialize test.pgdb, run a suite through minipg run test.pgdb -- go test ./..., and throw away the directory afterward. The Linux binary is static, and its native backend can run on a standard Linux runner without a privileged container or KVM device. The first command still pays for root extraction and initialization; caching the unpacked root helps repeated jobs.
The command set also covers routine administration: exec runs tools such as pg_restore with connection settings in place, dbs, create, and drop manage databases inside a cluster, and passwd rotates the generated superuser password. A cluster created for another PostgreSQL major can record that choice; fetch retrieves a compatible image root and MINIPG_OFFLINE=1 prevents network downloads. The current default is PostgreSQL 18, even though newer PostgreSQL releases may exist. An alternate major is a deliberate choice, not an automatic in-place upgrade of existing data files.
The project page’s live demo takes this portability idea one step further. It runs the Linux minipg build in a browser through hyper9’s web host and the v86 x86 emulator, with a terminal UI. That path is distinct from the native-host execution described above: the browser cannot open an ordinary TCP listener, so the demo uses a Unix socket, and it starts new databases from a prepared template to avoid a slow initdb inside v86. The download is about 35 MB, and the demo needs browser support for JavaScript Promise Integration. It is a demonstration of packaging reach, not a claim that a browser tab is a production database host.
The costs behind the shorter setup
Minipg trades deployment ceremony for work in its runtime. In the project’s Linux x86-64 native-backend measurements, a single-client select took 0.24 ms versus 0.11 ms for native PostgreSQL. Four-client select throughput was 3,800 versus 44,900 transactions per second. A new connection took 27 ms versus 2.3 ms. Those are project measurements for one backend and workload, not universal ratios for KVM, macOS, or Windows.
The expensive operation is PostgreSQL’s process-per-connection model crossing hyper9’s fork implementation. Hyper9 copies backend memory rather than sharing it copy-on-write, adding roughly 33 MB per connection in the project’s measurements. An idle server used about 375 MB resident memory. The configured guest-memory ceiling can look larger than actual use, but Windows Hypervisor Platform commits the guest memory up front, making its memory behavior a sharper constraint. A connection pool reduces repeated setup cost; opening a fresh connection on every request makes the penalty visible.
There are durability limits to weigh as well. Minipg’s manual describes crash tests that kill the server during writes and check PostgreSQL’s WAL recovery and indexes. PostgreSQL’s write-ahead log is what lets it replay committed changes after a crash. That testing is meaningful, but the project explicitly calls hyper9’s Linux personality young and recommends avoiding data that cannot yet be recreated. It is not claiming the operational maturity, high availability, or performance of a conventional PostgreSQL installation.
Where the model fits
Minipg is useful when an application or test needs PostgreSQL’s actual behavior—its SQL, extensions available in the bundled root, tools, and wire protocol—but setting up a separate service would be the larger burden. A project directory can carry a development cluster; a CI job can create a disposable one; a packaged tool can offer a local PostgreSQL-backed mode. The familiar client protocol means application code does not need a special database adapter.
It remains a server database behind the interface, not an in-process file format. The .pgdb must have one owner, a running server needs memory and a port, and backups must respect PostgreSQL’s consistency rules. Those details explain both the appeal and the boundary of the idea: minipg makes PostgreSQL feel easy to pick up for local work by packaging the runtime and automating its lifecycle, while leaving PostgreSQL’s real storage and client-server behavior intact.
For people who want to inspect or modify the implementation, the MIT-licensed source is written in Zig. Building it requires Zig 0.16, its hyper9 submodule, and tools that fetch and trim the PostgreSQL image root. That build process also shows why the distributable is much more than a postgres binary: it carries the userspace that binary expects, plus the runtime that lets that userspace execute on supported hosts.