NewsCrawler.org

How I Got Postgres into a Single Binary

The author describes miniPG, a single self-contained executable that embeds a full Postgres server and client. It works like the sqlite3 command-line tool: you point it at a directory, and that directory becomes the database. You can run queries right away, with no server to set up or keep running. The program compiles for Mac, Windows and Linux.

The command minipg serve turns miniPG into a regular Postgres server, and minipg run launches a program with environment variables that point it at this database. When the program exits, no database daemon is left running, and the data stays on disk. The author lists uses such as running self-hosted tools that need Postgres, embedding Postgres in other programs, learning, tests and agents.

The author reached this design through three attempts. PGlite[1], Postgres compiled to WebAssembly, supports only one connection, so an app that opened a second connection inside a transaction deadlocked. A second attempt ran Postgres inside v86[2], an x86 emulator, in a webview, but it took 7 seconds to accept a connection on an M3 MacBook. The third attempt, Hyper9[3], ran Postgres at near-native speed and cut startup to 800 ms, and the project was renamed miniPG because the PGlite name was already taken.

Repository miniPG github.com

A single self-contained executable with an embedded Postgres server and client; point it at a directory to get a database with no server to run.

Stars: 48Forks: 3License: MITUpdated:

Read the original progrium.xyzDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page