github progrium/minipg v0.4

one hour ago

minipg v0.4

PostgreSQL as a single executable. No server setup, no Docker. A .pgdb folder holds the whole database, and minipg app.pgdb opens a shell on it.

minipg app.pgdb                     # psql shell (creates app.pgdb if missing)
minipg url app.pgdb                 # postgres:// URL for your app
minipg run app.pgdb -- npm start    # your app, with DATABASE_URL set
minipg dump app.pgdb > dump.sql     # and minipg restore app.pgdb dump.sql

v0.4 is a hardening release. It follows a security review and several rounds of testing on real Linux (x86_64, arm64, AMD), macOS, and Windows hosts, and it fixes most of what those rounds turned up.

Changes to know about

  • No hypervisor now means h9's emulator, not its native backend. h9's native backend (now called sud) isn't a sandbox: anyone who can run code as the Postgres superuser (COPY ... TO PROGRAM, say) runs it on the host as you. minipg no longer picks it on its own. Without /dev/kvm, it uses h9's emulator, which is about 2.5 to 3x slower than KVM. For trusted workloads such as CI, set MINIPG_ENGINE=sud to get the faster native backend back. The server logs a warning when it's in use, and also when it's asked for but can't be used (anything but Linux x86_64).
  • Server memory follows max_connections. h9 copies each backend's memory at fork, so a connection costs about 33 MB, and the old fixed 2 GB machine ran out of memory at about 50 connections. The server's guest memory is now sized from max_connections, shared_buffers, and the worker settings: 5 GB with Postgres's defaults, used only as it's touched, up to h9's 32 GB (about 790 connections).
  • Windows clusters default to 20 connections. WHP commits guest memory up front, so new .pgdbs on Windows get max_connections = 20 and a 2 GB server machine. Raise it in postgresql.conf if you need more, and the machine grows to fit.

What's new since v0.3

Security

From a review of minipg's own code:

  • Image downloads are verified. Every registry digest must be sha256:<64 hex>, and the manifest, config, and each layer are hashed and checked before a root reaches the cache. Manifests are capped at 4 MiB.
  • Layer extraction is hardened. Entries under a symlinked parent are refused, so a layer can't delete or link host files through one. setuid, setgid, and sticky bits are dropped.
  • Stricter auth in minipg's client. Cleartext and MD5 auth are refused, SCRAM's server signature is required, and passwd sends a SCRAM verifier, not the password.
  • Private files stay private. Logs, stderr files, and restore's spooled dump are 0600. Private directories must be owned by you and not be symlinks, and temp files are created with their final mode and a random name.
  • serve warns when it listens off loopback without TLS. restore of a SQL dump runs psql in an empty temp directory instead of your working directory. CI runs with a read-only token.

Windows

  • Fixed initdb failing on v0.3's Windows zip. v0.3 was built from a hyper9 checkout missing a Windows file fix, so every file read as mode 0777 and initdb refused the data directory. make dist now refuses to build when a submodule isn't at its pinned commit.
  • Restarts after a crash are more reliable. A start that finds no guest memory free waits up to 20 s for a just-killed server's memory to be released, a command that catches a server idling out waits for it and starts a new one instead of failing with ServerStopping, and a server that stops before it's ready now shows its exit code and log instead of ServerStopping.
  • A crash in minipg itself is visible. A background server's stderr now goes to <key>.stderr beside its log, and a failed start prints it, so a panic no longer shows up as a bare "exit 3".

macOS

  • Gatekeeper. Release builds can be signed with a Developer ID and notarized (make dist SIGN_IDENTITY=... NOTARY_PROFILE=...). The README covers clearing the quarantine attribute on a browser-downloaded binary.
  • Control socket on long temp paths. When the socket path in macOS's $TMPDIR would overrun the 104-byte limit, the server binds it under /tmp/minipg-$UID/ instead (0700, checked).

Everywhere

  • restore from stdin works on macOS and Windows. A custom-format dump piped in is spooled under the temp directory's real path, which h9 can follow.
  • run --stop stops the server run started when the command exits, and passes SIGINT and SIGTERM on to the command. Use it under launchers that kill the process group, where the background server used to be left to crash-recover on every start.
  • Names resolve in the guest. Machines get the host's DNS servers, so wget in minipg exec, COPY FROM PROGRAM, dblink, and postgres_fdw can reach hosts by name.
  • Linked root caches. A root cache directory that is a symlink or junction no longer fails with NotDir.
  • status reports a server that dies just as it's asked as stopped instead of erroring.
  • Web demo: on phones and tablets the demo waits for a tap, so loading the page doesn't download 35 MB.
  • Under the hood: hyper9 bumped to main (22d395c), which renames its backends to engines, adds the emulator fallback, and turns a killed native-backend stub into its process being killed, so Postgres now runs crash recovery instead of holding that backend's locks forever. Zig is now 0.17.1.
  • Tests: the e2e and stress suites run on macOS and Windows (Windows e2e on a self-hosted WHP runner), every wait in the stress suite is bounded, and TestFetch no longer depends on what earlier runs left in the shared cache.

Known issues

minipg is still early, and hyper9's Linux ABI is young, so don't trust it yet with data you can't recreate. Every acknowledged commit has survived every crash round so far, on every platform. These turned up in the last test round:

  • AMD hosts: rare backend segfault or silent server death. In 2 of 6 long soaks on an AMD (c8a) host under KVM, a backend segfaulted during connection churn, or the server died with nothing in its log. It hasn't shown up on Intel, arm64, or the Mac, and looks like an older AMD-only h9 problem coming back.
  • Windows: a restart after a kill can hang. Once in 20 kill rounds, the restarted server never became ready. The Windows stress suite's all-processes kill, lost-update, and connection-limit tests still fail there.
  • On the native backend, Postgres is about 2x slower than native for one client and 6 to 12x slower under load, and new connections cost about 27 ms. The emulator is slower again.
  • JIT is off, because the root drops LLVM.

See Known limits for the rest.

Don't miss a new minipg release

NewReleases is sending notifications on new releases.