GitHub - mariuz/minibird

GitHub

14 min read Original article ↗

build release homebrew

Firebird SQL as a single executable. One static binary, no install, no system service: a .fbdb directory is the database.

minibird app.fbdb                     # SQL shell (creates the database)
minibird run app.fbdb -- npm start    # start a server, run your app, stop it
minibird serve app.fbdb               # server on 127.0.0.1 until Ctrl-C

Inspired by minipg (PostgreSQL as a single executable). Firebird makes this simpler: its engine runs embedded in the client tools, so most commands open the database file directly and need no server or virtual machine at all.

Install

Linux and macOS (and Windows in Git Bash):

curl -fsSL https://raw.githubusercontent.com/mariuz/minibird/main/install.sh | sh

Windows (PowerShell):

irm https://raw.githubusercontent.com/mariuz/minibird/main/install.ps1 | iex

The scripts download the latest release's binary for your system, check it against the release's SHA256SUMS, and install it as minibird:

  • install.sh: in ~/.local/bin, or /usr/local/bin when run as root. It tells you if that folder isn't on your PATH.
  • install.ps1: in %LOCALAPPDATA%\Programs\minibird, which it adds to your user PATH.

Both read MINIBIRD_INSTALL_DIR (another folder) and MINIBIRD_VERSION (a release such as v0.3.0 instead of the latest):

curl -fsSL https://raw.githubusercontent.com/mariuz/minibird/main/install.sh | MINIBIRD_INSTALL_DIR=/opt/bin MINIBIRD_VERSION=v0.3.0 sh

To read a script before running it, download it first: curl -fsSLO https://raw.githubusercontent.com/mariuz/minibird/main/install.sh.

Homebrew

On macOS and Linux, minibird's own repository is a Homebrew tap:

brew tap mariuz/minibird https://github.com/mariuz/minibird
brew trust mariuz/minibird
brew install mariuz/minibird/minibird

Recent Homebrew versions only load formulae from third-party taps that you trust (brew trust); with an older one, skip that line.

brew upgrade minibird updates it. For a Homebrew install, minibird update and the update notice point you to brew upgrade instead of replacing the binary themselves.

Manual download

Or take the binary for your system from the releases and put it anywhere:

platform binary
Linux x86-64 (glibc 2.35+) minibird-linux-x64
Linux arm64 (glibc 2.35+) minibird-linux-arm64
macOS Apple Silicon (11+) minibird-macos-arm64
macOS Intel (11+) minibird-macos-x64
Windows x64 (10+; also Windows on Arm, emulated) minibird-windows-x64.exe
curl -fsSLo minibird https://github.com/mariuz/minibird/releases/latest/download/minibird-linux-x64
chmod +x minibird

On macOS, a binary downloaded with a browser is quarantined: run xattr -d com.apple.quarantine minibird-macos-* once (it isn't notarized). The install script and minibird update aren't affected.

To uninstall, delete the binary and the cache (~/.cache/minibird, ~/Library/Caches/minibird or %LocalAppData%\minibird). Your databases are the .fbdb directories, wherever you made them.

Updating

minibird update            # replace this binary with the latest release
minibird update --check    # only say whether there is one
minibird update v0.3.0     # a given release (also to go back)

update downloads the release's binary for your system, checks it against SHA256SUMS, runs it once to see that it works, and then replaces the minibird you ran (through a symlink too). It needs the rights to write that file: an install in /usr/local/bin needs sudo minibird update. A Homebrew install is updated with brew upgrade minibird.

Automatic updates: once a day minibird asks GitHub, in the background, which release is the latest: one small request to github.com, which sends nothing about your databases. When there is a newer one, the next command run in a terminal says so. With MINIBIRD_AUTO_UPDATE=1 minibird installs it instead, taking effect from the following command. MINIBIRD_NO_UPDATE_CHECK=1 turns the check off; builds without a release version (dev) never check.

How it works

  • The binary embeds the official Firebird 5.0.4 release for its platform, trimmed to the server, the tools and their plugins: 17 to 21 MB, zstd-compressed. The Linux release expects libtommath and ICU from the system, so those are bundled too; the macOS and Windows releases bring their own.

  • On first use it is extracted to the user cache directory (~/.cache/minibird/, ~/Library/Caches/minibird/, %LocalAppData%\minibird\; MINIBIRD_CACHE overrides this), one directory per Firebird runtime. Later runs reuse it.

  • A database directory holds:

    file
    minibird.json user, password (generated; minibird passwd changes it), fixed port (0 = any free port), listen address
    data.fdb the database (UTF8)
    security5.fdb this database's own users (security6.fdb with Firebird 6; minibird.json names it)
    firebird.conf your Firebird settings, copied into the generated config at each start (see below)
    run/ runtime state: generated FIREBIRD root, locks, server log
  • Each .fbdb has a process lock. Its holder either opens data.fdb embedded (sql, schema, backup, tool, ...) or runs the server (serve, run). While a server runs, the other commands connect to it over TCP instead.

  • The server is Firebird SuperServer bound to 127.0.0.1 (or the --listen address), with SRP authentication against the database's own security database. It stops when minibird exits. If minibird is killed, the server goes with it on Linux (parent-death signal) and Windows (job object); on macOS the next minibird command on that database stops it.

  • run/root is the database's FIREBIRD directory: its own firebird.conf (minibird's settings, then your firebird.conf) and databases.conf, with links to the runtime (symbolic links; on Windows junctions and copies, which need no administrator rights). On Windows each server also gets its own IpcName / RemotePipeName, so it doesn't clash with other servers or an installed Firebird.

  • Your firebird.conf can set anything except the settings minibird writes: RemoteServicePort, RemoteBindAddress, SecurityDatabase, DatabaseAccess, ServerMode, AuthServer, UserManager (on Windows also IpcName, RemotePipeName), and WireCrypt when the server listens beyond this machine. minibird leaves those lines out when it copies the file (shown as comments in run/root/firebird.conf), because Firebird doesn't reliably pick one of two values: the first on Linux, the last on Windows. Use --port, --listen and minibird.json for those.

  • Stopped databases are plain directories: copy, move or archive them. minibird.json contains the password, so treat the directory as a secret.

Commands

minibird <db.fbdb> [isql options]        open an SQL shell (creates the database)
minibird init <db.fbdb>                  create a database
minibird serve [--port N] [--listen ADDR] [--idle DURATION] <db.fbdb>
                                        run a server until Ctrl-C (or idle)
minibird run [--port N] [--listen ADDR] <db.fbdb> -- <command> [args]
minibird sql <db.fbdb> [isql options]    open an SQL shell
minibird schema <db.fbdb>                print the database's DDL (isql -x)
minibird dump [--schema-only | --data-only] [--table T]... [-o file] <db.fbdb>
                                        print the schema and data as SQL
minibird csv [--no-header] [-o file] <db.fbdb> <table | "SELECT ...">
                                        print a table or query as CSV
minibird backup <db.fbdb> <file.fbk>     back up with gbak
minibird restore [--replace] <file.fbk> <db.fbdb>
minibird tool <db.fbdb> <program> [args] gbak, gfix, gstat, nbackup, isql,
                                        fbsvcmgr, fbtracemgr; "@db" = the database
minibird status <db.fbdb>
minibird passwd [--stdin] <db.fbdb>      give the database's user a new password
minibird version
minibird update [--check] [--force] [vX.Y.Z]
minibird upgrade-db [--check] [--force] [--from old-minibird] <db.fbdb>

The short form minibird <name> needs a name ending in .fbdb (or an existing database), so a mistyped command is an error, not a new database; minibird sql <name> takes any name.

run gives the command these variables:

variable example
DATABASE_URL firebird://SYSDBA:<password>@127.0.0.1:34421/app
FIREBIRD_DSN 127.0.0.1/34421:app (isql / fbclient form)
FIREBIRD_HOST, FIREBIRD_PORT, FIREBIRD_DATABASE 127.0.0.1, 34421, app
ISC_USER, ISC_PASSWORD read by fbclient-based drivers
MINIBIRD_CLIENT_LIB the bundled client library (libfbclient.so.2, libfbclient.dylib, fbclient.dll), for drivers that load one

The database name on the server (app above) is the directory name without .fbdb.

Examples:

minibird app.fbdb -i schema.sql                # run a script
minibird tool app.fbdb gfix -sweep @db         # sweep
minibird tool app.fbdb nbackup -B 0 @db full.nbk
minibird run app.fbdb -- python -c 'import os; print(os.environ["DATABASE_URL"])'

Stopping an idle server

serve --idle DURATION stops the server once no client has been connected for that long, e.g. for a development database that shouldn't keep running after you're done:

minibird serve --idle 10m app.fbdb

It looks for clients every third of the duration (between 1 and 30 seconds), counting every connection but its own and Firebird's internal ones, so other minibird commands using the server keep it up too. The server stops cleanly, and serve exits with status 0. Durations are written like 30s, 10m or 1h30m.

Changing the password

minibird init gives the database's user (SYSDBA) a random password and saves it in minibird.json. minibird passwd changes it, in the database's security database and in minibird.json:

minibird passwd app.fbdb                       # a new random password, printed
printf '%s\n' "$NEW_PASSWORD" | minibird passwd --stdin app.fbdb

--stdin reads one line, so the password stays out of your shell history and the process list. It works with the database stopped and while serve or run holds it; a program that run started still has the old password in its environment.

Listening beyond this machine

Servers listen on 127.0.0.1. To let other machines connect, give serve or run an IP address of this machine, or 0.0.0.0 for every interface (an IPv6 address works too):

minibird passwd app.fbdb                       # first: not the password you've been sharing
minibird serve --listen 0.0.0.0 --port 3050 app.fbdb

Clients then connect to this machine's address, e.g. isql -user SYSDBA -password … 192.168.1.10/3050:app. "listen" and "port" in minibird.json make those the defaults.

For any address but loopback, minibird requires encrypted connections (WireCrypt = Required; your firebird.conf can't turn it off) and only SRP logins. Firebird 3 and newer clients encrypt by default; older clients and drivers that turn encryption off can't connect. The password is the only thing between the network and the database, so use a strong one, and a firewall where you can. Some drivers only encrypt with the weak RC4 cipher (Arc4, see drivers); add WireCryptPlugin = ChaCha64, ChaCha to your firebird.conf to refuse it.

Upgrading a database to a newer Firebird

Each Firebird major version has its own on-disk structure (ODS): Firebird 5 writes ODS 13.1, Firebird 6 will write ODS 14, and an engine can't open another major's files. When a minibird with a newer Firebird meets an older database, commands stop with a message pointing here instead of Firebird's "unsupported on-disk structure":

minibird upgrade-db --check app.fbdb    # what it would do
minibird upgrade-db app.fbdb
  • A newer Firebird major: minibird downloads the last minibird release with the database's Firebird (checksum-verified, like minibird update), backs the data and security databases up with it, restores them with its own Firebird, and moves the old files to app.fbdb/pre-upgrade/. Give --from path/to/old-minibird to use a minibird you already have instead. Data, sequence and identity values and the password all carry over.
  • A newer minor (ODS 13.0 from Firebird 4 under Firebird 5): upgraded in place with gfix -upgrade, after copying the files to pre-upgrade/.
  • --force rebuilds through a backup and restore even when nothing needs upgrading.

Stop the database's server first. The original files stay untouched until the new ones are ready; delete pre-upgrade/ once you're happy. A database from a newer Firebird than yours is refused: use a newer minibird.

This is tested in CI against the latest Firebird 6 development snapshot: Firebird 6 isn't released yet, so minibird itself still ships Firebird 5.

Exporting data

minibird dump writes the database as SQL: the schema (isql -x) with the rows as INSERT statements, and the sequence and identity values. Load it into a new database with isql:

minibird dump app.fbdb > app.sql               # or -o app.sql
minibird init copy.fbdb
minibird sql copy.fbdb -q -b -i app.sql        # -b: stop at the first error

The rows go in after the tables and before indexes, foreign keys and triggers, so they load in any order and no trigger changes them.

  • --schema-only is the same as minibird schema.
  • --data-only writes only the rows and the sequence and identity values, for a database that already has the schema; with foreign keys, load tables in an order they accept.
  • --table T (repeatable) dumps only those tables' rows and identity values.

All of Firebird's types are written exactly: NUMERIC and INT128 as decimals, DECFLOAT, dates and times as Firebird's own text (time zone regions included), text and binary blobs of any size. Computed columns are left out (Firebird computes them again), and so are array columns, with a warning. A dump reads the database through a server: the running one, or a temporary one minibird starts on 127.0.0.1.

minibird csv writes one table, or the rows of any SELECT, as CSV with a header row:

minibird csv app.fbdb customers > customers.csv
minibird csv --no-header app.fbdb "select id, name from customers where active" -o active.csv

NULL is an empty field, binary values are hex, and dates and times are ISO 8601. A table name matches without regard to case.

Using it from your code

minibird run starts the server and gives your program its address and login in the environment (see the table above). These examples, in examples/, run in CI on Linux, macOS and Windows:

language driver how it connects encryption
Go github.com/nakagami/firebirdsql (pure Go) DATABASE_URL without firebird:// ChaCha64
Python firebird-driver (official) FIREBIRD_DSN, ISC_USER, ISC_PASSWORD, and the bundled client library from MINIBIRD_CLIENT_LIB ChaCha64
Node.js node-firebird (pure JavaScript) FIREBIRD_HOST, FIREBIRD_PORT, FIREBIRD_DATABASE, ISC_USER, ISC_PASSWORD Arc4 (RC4) only
minibird run app.fbdb -- go run ./examples/go
minibird run app.fbdb -- python examples/python/app.py     # pip install -r examples/python/requirements.txt
minibird run app.fbdb -- node examples/node/app.js         # cd examples/node && npm install

Go, in short:

dsn := strings.TrimPrefix(os.Getenv("DATABASE_URL"), "firebird://")
db, err := sql.Open("firebirdsql", dsn) // import _ "github.com/nakagami/firebirdsql"

Python:

from firebird.driver import connect, driver_config
driver_config.fb_client_library.value = os.environ["MINIBIRD_CLIENT_LIB"]
con = connect(os.environ["FIREBIRD_DSN"], user=os.environ["ISC_USER"],
              password=os.environ["ISC_PASSWORD"], charset="UTF8")

Node.js (column names come back in upper case):

Firebird.attach({ host: process.env.FIREBIRD_HOST, port: Number(process.env.FIREBIRD_PORT),
  database: process.env.FIREBIRD_DATABASE, user: process.env.ISC_USER,
  password: process.env.ISC_PASSWORD, encoding: 'UTF8' }, (err, db) => { /* ... */ });

Building

Go 1.24+, bash and curl. TARGET is one of linux-x64, linux-arm64, macos-x64, macos-arm64, windows-x64 (default linux-x64):

make build                      # downloads Firebird, packs the runtime, builds ./minibird
make test                       # end-to-end test (tests/e2e.sh)
make runtime build TARGET=macos-arm64

Every target cross-compiles from any system, with these needs for its runtime: Linux targets copy the build host's libtommath1 and ICU (libicu*), so build them on that architecture; macOS packages are unpacked with pkgutil (macOS) or 7z; Windows zips with Python. The runtime in runtime/ is for the last target fetched: run make runtime when switching.

FB_VERSION / FB_BUILD select another Firebird release (FB_VERSION=5.0.4 FB_BUILD=1812 by default). CI builds and tests each target on its own runner (Linux inside Ubuntu 22.04, so the binaries need glibc 2.35 or newer: Ubuntu 22.04+, Debian 12+, RHEL 10+), on every push to any branch and on pull requests. It can also be run by hand (Actions → build → Run workflow), which never releases.

Releasing

Releases are made by CI from main; nobody needs to push a tag.

  1. Set the new version in VERSION (for example 0.3.0, without the v). It is also what minibird version prints.
  2. Add a section for it at the top of docs/CHANGELOG.md, headed ## v0.3.0 — <date> (or rename the ## Unreleased section collected since the last release). Everything up to the next ## heading becomes the release notes.
  3. Push to a branch first if you want to see CI pass, then push (or merge) to main.

On a push to main, the release job of .github/workflows/build.yml runs after all five builds and their tests pass. (The install job tests the install scripts and the Homebrew formula against the release already published, so it doesn't hold a new release back.) If the tag v<VERSION> doesn't exist yet, it creates it on that commit and publishes the GitHub Release with the five binaries and their SHA256SUMS, which the install scripts and minibird update check. It then writes Formula/minibird.rb for that release (scripts/homebrew-formula.sh) and commits it to main as github-actions[bot], so pull before your next change. If it does exist, it does nothing, so ordinary pushes to main don't release.

  • A build fails: nothing is tagged or released. Fix it and push again.
  • No changelog section: the release gets GitHub's generated notes (a link to the commits) instead.
  • Fixing a released version: a tag is never moved or released twice, so bump VERSION for the fix. To change only a release's notes, edit them on its GitHub page and in docs/CHANGELOG.md.
  • Pushing a v* tag yourself also works: CI builds, tests and releases that tag. The binaries still print the version in VERSION, so tag a commit where the two match.
  • A new Firebird release: change the FB_VERSION / FB_BUILD defaults in scripts/fetch-runtime.sh (CI uses them), then release as above. Databases keep working, and users get a new runtime cache directory.

Limits

  • No Windows arm64 build: Firebird 5 has none.
  • On Windows, a server that still has clients connected when minibird stops it asks for confirmation in a dialog nobody sees, so minibird ends it after 5 s. Firebird's on-disk format survives that, but open transactions are rolled back. With no clients connected it shuts down cleanly.
  • Only one minibird process owns a database at a time, as with minipg; other processes reach it through the server it runs.
  • Early software. Firebird itself is mature; the wrapper is new.

License

minibird is MIT licensed. The embedded Firebird is under the Initial Developer's Public License and InterBase Public License (license files in the extracted runtime); ICU is under the Unicode license and libtommath is public domain.