Minipg:单文件可执行的 PostgreSQL
Minipg: PostgreSQL as a Single Executable

原始链接: https://progrium.github.io/minipg/

minipg 将 PostgreSQL 打包为一个可执行文件,使用 .pgdb 目录存放数据、配置、凭据和版本。命令如 minipg app.pgdb open psql、执行 SQL、提供 URL、serve、运行应用、dump/restore;服务器按需启动并空闲。它内嵌 Docker Hub 的 postgres:18-alpine 镜像,并通过 h9 运行,其 Linux 人格在宿主 hypervisor 上执行 Alpine 的 Postgres 二进制文件,由 Plan 9 内核处理系统调用——无需启动 Linux 内核、VM 镜像或 Docker。.pgdb 包含 minipg.toml 和 pgdata;停止的数据库可像目录一样复制,集群使用 C.UTF-8。工具运行在短生命周期的 h9 机器中;通过锁强制每个 .pgdb 只有一个进程。平台包括带 KVM 或原生后端的 Linux x86_64/arm64、macOS Apple Silicon,以及通过 v86 的浏览器。它还很早期,且比原生慢,尤其在负载下,因此避免用于不可替代的数据;请通过 GitHub 报告 bug。

Hacker News 最新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Minipg:PostgreSQL 作为单一可执行文件 ( progrium.github.io ) 11 分 by rguiscard 1 小时前 | 隐藏 | 过去 | 收藏 | 1 评论 帮助 anilgulecha 25 分钟前 [–] 对于在这个领域工作的人,我可以请求一个 MySQL/mariadb-lite 吗? pglite 对于浏览器 / 测试模拟 PG 很好。MySQL 在浏览器中没有同样好的方案。最接近的是 https://github.com/ephpm/litewire ,但它并不是真正的 MySQL 完整版。 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文
minipg: PostgreSQL as a single executable

Jeff Lindsay, h.d.a.

About

minipg is PostgreSQL as one executable, ready to use, with no server to configure. A .pgdb directory is the database: its data, config, credentials, and Postgres version all live inside it, and minipg app.pgdb opens a psql shell on it. A server starts when a command needs one and stops on its own when it's idle.

minipg embeds Docker Hub's postgres:18-alpine image and runs it with h9, used as a Zig library. h9's Linux personality runs Alpine's own Postgres binaries directly on the host's hypervisor, with h9's Plan 9 kernel answering their system calls. There's no Linux kernel to boot, no VM image, and no Docker.

Demo

The demo downloads about 35 MB. It needs JavaScript Promise Integration, which Chrome and Edge have from version 137; other browsers are getting it. It can also be opened on its own page.

The demo runs minipg's Linux build, which runs inside the Postgres image itself. It starts Postgres as ordinary processes and serves on a unix socket, since a page has no TCP. New databases come from a template cluster made at build time, because initdb takes half a minute on v86.

Using It

minipg app.pgdb                     # psql shell (creates app.pgdb if missing)
minipg app.pgdb "select 1"          # one statement
minipg url app.pgdb                 # postgres://postgres:[email protected]:54321/app
minipg serve app.pgdb               # an explicit foreground server
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

A .pgdb holds minipg.toml (settings and the generated superuser password) and pgdata/, Postgres's data directory as plain files. A stopped one can be copied like any directory. New clusters use Postgres's builtin C.UTF-8 locale, which sorts the same on every platform.

In CI, the Linux binary is static and needs no privileges or devices: without /dev/kvm, h9 runs Postgres on its native backend. A test job can be as small as:

minipg init test.pgdb
minipg run test.pgdb -- go test ./...

The README lists every command, and the manual is the full guide.

How It Works

Exactly one process runs Postgres for a .pgdb, enforced by a lock. It holds the server's h9 machine, whose Linux root is the unpacked image and whose writable working directory is the .pgdb. The image's docker-entrypoint.sh initializes the cluster on first start. Commands never host Postgres themselves. If no server is running, they start one in the background and use it. psql, pg_dump, and the other tools each run in their own short-lived h9 machine (about 90 ms to start) over the same root.

Linux x86_64KVM, or h9's native backend without it (Linux 5.11 or later)
Linux arm64KVM
macOS (Apple Silicon)Hypervisor.framework
The browserh9's web host, v86, and minipg's Linux build

Source Code

The source is on GitHub, under the MIT license. Building needs Zig 0.16, plus curl, jq, tar, and xz for the root:

git clone --recursive https://github.com/progrium/minipg
cd minipg
make build         # pulls the root for this host's arch, builds ./minipg
make root ARCH=386
make web           # this page's demo, in .zig-out/web

Warning!

minipg is early, and h9's Linux personality is young. On h9's native backend, Postgres is about 2x slower than native for one client, and slower under load. Don't trust it with data you can't recreate yet.

Please report bugs and send questions through GitHub issues.

  • h9, which runs native 9front executables, and Linux ones, on host hypervisors
  • PostgreSQL and Docker Hub's postgres image
  • v86, the x86 emulator the demo runs on
  • xterm.js, the demo's terminal
联系我们 contact @ memedata.com