db-branch: Self-Hosted MySQL and PostgreSQL Branches in Seconds via ZFS Clones
db-branch is a self-hosted, Apache-2.0 tool that creates instant copy-on-write branches of MySQL and PostgreSQL databases using ZFS clones, so a large database can be copied in seconds with zero bytes duplicated at creation. It is currently in Beta, and its author presented it on Hacker News as a way to give AI agents and CI pipelines disposable database copies without touching production.
What db-branch does
db-branch creates a copy-on-write branch of a database in seconds by cloning a ZFS snapshot, and each branch runs as its own independent database server process. The project describes the core promise as: "Test a migration, let an AI agent loose, or give every pull request its own copy of the database."
Key capabilities listed in the repository:
- Branches in seconds. On the project's own 3-node test cluster, a PostgreSQL branch is ready in about 0.5 seconds and a MySQL branch in about 3 seconds, with 0 bytes copied at creation.
- Reset and expire.
branch resetreturns a branch to its creation state;--ttldeletes a branch automatically. - Checkpoints.
branch checkpointsaves a running branch's state instantly, andbranch restoreputs it back. Restoring replaces the current state, and every existing checkpoint stays restorable. - Per-branch upgrades.
branch upgrademoves a single branch to a newer MySQL or PostgreSQL version while the base and other branches stay put. A checkpoint is saved first, and a failed upgrade rolls back automatically. - Multiple engine versions side by side. MySQL and PostgreSQL runtimes are installed by version and can coexist.
- One interface everywhere. CLI, REST API, web console, and an MCP server all use the same API.
- Single node or cluster. A Raft cluster of VMs with optional ProxySQL routing so applications keep one address.
How db-branch works under the hood
A base is a ZFS dataset holding a loaded database, and a branch is a ZFS clone of a base snapshot, so creating one copies nothing. Each branch runs its own database server on its own port, started through a systemd template unit that switches ports per branch.
ProxySQL sits in front of the branch processes so clients do not have to change port numbers. Branches are routed by connecting user or by a query comment of the form /*db_branch='name'*/. According to the author, this works for PostgreSQL as well as MySQL, using ProxySQL 3.x's PostgreSQL protocol support. Several nodes form a Raft cluster that shares bases, branches, settings, and users, with ZFS send/recv used for cluster data movement.
Use cases: AI agent sandboxes, per-PR databases, upgrade checks
The project targets three primary workloads.
AI agent sandboxes. The built-in MCP server lets an LLM agent create a branch, run a risky query or migration on it, and delete the branch, so production data is never touched. The author framed this as a core motivation:
Pointing an agent at production or staging directly is dangerous. With a branch, even if the agent runs something destructive (a DROP, a massive UPDATE), you just throw the branch away or roll back to a snapshot.
A database per pull request. Each CI run or PR gets its own copy of a large database, ready in seconds, and removed by --ttl when it is no longer needed.
Version-upgrade checks. A major-version upgrade, for example MySQL 8.0 to 8.4, can be run on one branch first with branch upgrade --check-only to see what it would run into before touching the base.
Basic workflow and commands
Installation requires Ubuntu 24.04 LTS or 26.04 LTS and a ZFS pool. db-branch is distributed through an apt repository, and the repository signing key fingerprint is 3F404C4E5D49FA653F8385692C6E89E341D4D7A5. db-branch init --pool <zpool> prints the initial admin password once.
A typical first branch looks like this:
db-branch runtime install postgres@18.6
db-branch base create prod --runtime postgres@18.6 --dump prod.sql.gz
db-branch branch create feature-x --base prod --ttl 72h
db-branch branch dsn feature-x
db-branch branch checkpoint feature-x --name before-migration
db-branch branch restore feature-x before-migration
db-branch branch reset feature-x
db-branch branch delete feature-x
MySQL works the same way, for example mysql@8.4.13. Installable versions are listed with db-branch runtime available.
Limitations and trade-offs
The author is explicit about three constraints.
Base snapshots come from a cleanly shut-down database. For consistency, snapshots are taken from a cleanly shut-down database instance. This does not mean stopping production: the intended pattern is to stop a read replica and snapshot that, or to use an instance restored from a regular dump or backup as the base.
Memory, not disk, is the real cost. Copy-on-write keeps disk usage low, but every branch is a separate database process, so per-process memory grows with the number of branches. The author's guidance:
Memory is the real cost: CoW keeps disk usage low, but every branch is a separate DB process, so per-process memory grows with the number of branches. So we recommend keeping the DB-side caches (InnoDB buffer pool, PostgreSQL shared_buffers) small and giving most of the memory to the ZFS ARC. Clones share unmodified blocks, so data cached in the ARC is shared across branches, instead of every branch holding its own copy of the same data in its own DB cache.
Heavy writes still consume disk. Copy-on-write only shares blocks that have not been modified, so a branch that writes a lot consumes that much space.
Editions, licensing, and monetization
db-branch has no hosted or cloud version. The core repository is Apache-2.0 and includes branches, bases, runtimes, clustering, CLI, API, web console, MCP, monitoring, notifications, anonymous (no sign-in) branches with limits, scheduled base refresh, and backup of cluster state.
| Edition | Contents | License |
|---|---|---|
| Core (this repository) | Branching, bases, runtimes, clustering, CLI, API, web console, MCP, monitoring, notifications, anonymous branches, scheduled base refresh, cluster state backup | Apache-2.0 |
| Free modules (same apt repository) | proxysql, greenmask, greenmask-mysql, anon (routing and data masking) |
Free |
| Paid modules | Auth/SSO, audit, history, diff, FSx storage | Closed source, self-hosted, license key (monthly or yearly) |
The author described the split as a sustainability decision: the core branching engine and clustering are fully open source and free, while per-query recording and restore (the History Module), enterprise user management, SSO, and auditing are planned as commercial modules. A governed masking workflow is planned as an opt-in beta and is not part of any plan yet. Paid modules can be trialed for one month without a key.
Trying it without a server
Two evaluation paths are offered. A live console demo at https://demo.db-branch.com/ runs entirely in the browser and creates nothing real. For a local test on macOS or Windows, a single Multipass command launches an Ubuntu 24.04 VM, installs db-branch, initializes it on a file-backed ZFS pool, and loads a small sample base named shop running MySQL 8.4:
multipass launch 24.04 --name db-branch-eval --memory 4G --disk 30G --timeout 900 \
--cloud-init https://raw.githubusercontent.com/db-branch/db-branch/main/scripts/eval-cloud-init.yaml
The VM's initial console credentials are admin / admin, and the console asks for a new password at first sign-in. The history module is enabled in the evaluation environment, and paid modules run for 30 days without a key. Because the pool is a file, it is slower and not intended for real data. On Apple Silicon and other arm64 machines the setup downloads roughly 800 MB for MySQL versus about 80 MB on Intel, because Oracle ships no minimal build for arm64. If setup fails, /etc/motd reports it and sudo tail -n 30 /var/log/cloud-init-output.log shows why.
What Hacker News commenters raised
The Hacker News thread drew 31 points and 9 comments. Several commenters asked technical questions that were not answered in the visible thread, so they remain open in the source material.
- Merging changes back. One commenter asked whether it is possible to merge changes from a clone or branch back to the official copy: "Is it possible to merge changes from a clone/branch back to the 'official copy'?" No answer appears in the thread.
- PostgreSQL 18 native clone support. Another asked whether db-branch uses PostgreSQL 18's
file_copy_method = cloneunderneath or implements its own mechanism: "Postgres 18 has file_copy_method = clone for this, is that used underneath or did you implement your own own?" No answer appears in the thread. - MVCC integration. A third asked whether the tool hooks into PostgreSQL and MySQL's MVCC: "This is interesting. Does it hook into Postgres and MySQL's MVCC?" No answer appears in the thread.
Two commenters compared db-branch to existing practice. One described previously maintaining a custom script that cloned the database for feature work involving schema or data mutation, and noted that AI-assisted development has reduced how often they need it:
Super interesting, I had my own dumb script that clones the DB whenever I needed to work in a feature that requires some sort of DB mutation, some times with a lot of them going, so this does sound useful. Having said that lately with the speed of AI assisted development I do this less and less...
Another pointed to an existing open-source alternative for cheap database clones, postgres.ai's Database Lab, saying they had recently set it up at work for the same purpose.
The author also positioned db-branch against managed branching services. Per-PR preview environments are common, but the database is usually still shared; PlanetScale, Neon, and Aurora's fast clone solved this with Git-like branching, but those are managed services tied to specific cloud vendors. db-branch targets the cases those services do not cover: cost-sensitive deployments, fully air-gapped on-premises environments, and local development on a laptop.
Project status and governance
db-branch is in Beta, and the project warns that APIs and command-line details may still change before 1.0. It is an independent open-source project built from scratch. Contributions require a DCO sign-off (git commit -s), security issues should go through private vulnerability reporting rather than public issues, and no support is promised. Design and reference documents under docs/ are written in Japanese, while English user documentation is hosted at https://db-branch.com/docs/.