All Today

🗄️ minipg: PostgreSQL as a single executable, with the database in one folder

· 3 min

GitHub preview card of the minipg repository

In brief


[minipg](https://progrium.github.io/minipg/) lets you use the PostgreSQL database much like a simple command-line program. 🗄️ Instead of installing and configuring a server, you run one file: the command minipg app.pgdb creates the database if it is missing and opens an SQL shell on it. Everything belonging to it sits in that folder, which can be copied like any other once stopped. The server starts when a command needs it and shuts down by itself when idle. The code by [progrium](https://github.com/progrium/minipg) is on GitHub under the MIT license. It looks suited to local development and automated tests. The author warns that the project is still young. ⚠️


Inside the file is the postgres:18-alpine image from Docker Hub. It is run with hyper9, or h9: Alpine's own Postgres binaries execute directly on the machine's hypervisor, and a kernel from h9 answers their system calls. According to the project page, no Linux kernel, VM image or Docker is needed.

**Working with it** 💻

- minipg url app.pgdb prints a connection address with password for your application.

- minipg run app.pgdb -- npm start launches a program with the DATABASE_URL variable set.

- minipg dump and minipg restore save and load data.

- init --pg 17 creates a database on another major version, downloading it once.

The folder contains a configuration file with the generated superuser password and the data directory. By default Postgres listens only on the local machine, and applications authenticate with the password. A database that is running should be backed up with pg_dump, because a raw copy is not guaranteed to be consistent then. With no client connections, the server stops after 60 seconds by default.

**Platforms** 🧩

On x86_64 Linux, minipg runs with KVM or through its own native backend from kernel 5.11, without special privileges, which also makes it usable for test jobs in continuous integration. On Windows 10 version 1803 or later, the Windows Hypervisor Platform feature must be switched on. Builds exist for Apple Silicon macOS and ARM Linux, but the README says they have not been run in testing. Windows on ARM is not supported. The first start unpacks about 90 MB. To look first, there is a [browser demo](https://progrium.github.io/minipg/demo/) on the project page that downloads about 35 MB and currently requires Chrome or Edge 137 or newer.

**Limits** ⚠️

On the native backend without KVM, the project says Postgres is about 2x slower than native for a single client and 6 to 12x slower under load, and a new connection costs around 27 milliseconds. Applications without connection pooling will notice. No measurements are given yet for KVM or Apple's hypervisor. Just-in-time compilation is switched off. On Windows, each server reserves 2 GB of memory up front and each running tool 1 GB, so an 8 GB machine can handle three or four servers at most. The project describes h9 as a research prototype. Anyone looking for a database to run permanently with irreplaceable data should therefore wait. Building from source requires Zig 0.16.

Sources

Open in the interactive reader →

This post was selected, researched, written and rated by AI. The AI can be wrong: check the sources. Imprint, privacy policy and terms of service