db-branch 用 ZFS 秒级克隆数据库分支
开源项目 db-branch 基于 ZFS 写时复制克隆,为 MySQL 与 PostgreSQL 在数秒内创建零拷贝的数据库分支,无需复制数据即可测试迁移、供 AI 智能体自由操作或为每个 PR 提供独立数据库副本。项目采用 Apache-2.0 协议、自托管部署,目前处于 Beta 阶段,API 与命令行细节在 1.0 前仍可能变动。
报道正文
本文目录5 个章节
db-branch
Instant database branches for MySQL and PostgreSQL, on your own servers.
Test a migration, let an AI agent loose, or give every pull request its own copy of the database. db-branch creates a copy-on-write branch of a large database in seconds, with nothing copied. Break it, reset it, throw it away. Built on ZFS clones, self-hosted, Apache-2.0.
Status: Beta. db-branch is usable today, but APIs and command-line details may still change before 1.0. It is an independent open-source project, built from scratch.

Try it
- In your browser, 0 minutes. A live console demo runs entirely in the page (nothing real is created): https://demo.db-branch.com/
- On a Mac or Windows machine, about 2 minutes. db-branch needs Linux and ZFS, so run it in an Ubuntu VM with Multipass. One command makes the VM, installs db-branch, initialises it on a file-backed ZFS pool and loads a small sample base,
shop(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
multipass exec db-branch-eval -- cloud-init status --wait # wait for the setup (about two minutes)
multipass exec db-branch-eval -- cat /etc/motd # console URL and sign-in (admin / admin), or what failed
multipass shell db-branch-eval # then: sudo db-branch branch create try --base shop --ttl 1h --recordOn Windows (PowerShell or cmd), put the multipass launch command on one line and drop the \:
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 history module is turned on, and the paid modules run for 30 days without a key.
--recordrecords a branch so it can be restored to any point. - The pool is a file, so it is slower and not meant for real data. The first admin password is
admin; the console asks for a new one at the first sign-in. - On Apple Silicon (and other arm64 machines) the setup downloads about 800 MB for MySQL, against 80 MB on Intel, because Oracle ships no minimal build for arm64.
--timeout 900keepslaunchfrom giving up on a slow connection. - If the setup fails,
/etc/motdsays so, andsudo tail -n 30 /var/log/cloud-init-output.login the VM shows why. - Delete the VM with
multipass delete --purge db-branch-eval.
- On your own Ubuntu server. See Install.
Use cases
- 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.
- A database per pull request. Each CI run or PR gets its own copy of a large database, ready in seconds, and removed by
--ttlwhen it is no longer needed. - Version-upgrade checks. Run a major-version upgrade (for example MySQL 8.0 to 8.4) on one branch first, with
branch upgrade --check-onlyto see what it would run into, before touching the base.
What it does
- Branches in seconds. On our own 3-node test cluster a PostgreSQL branch is ready in about 0.5 s and a MySQL branch in about 3 s, with 0 bytes copied at creation (copy-on-write).
- Reset and expire.
branch resetreturns a branch to its creation state;--ttldeletes it automatically. - Checkpoints.
branch checkpointsaves a running branch's state instantly;branch restoreputs it back. Restoring replaces the current state, and every checkpoint you already have stays restorable. - Per-branch upgrades.
branch upgrademoves one branch to a newer MySQL or PostgreSQL version while the base and the other branches stay put. A checkpoint is saved first, and a failed upgrade rolls back by itself. - MySQL and PostgreSQL, several versions at once. Engine runtimes are installed by version and can live side by side.
- One interface everywhere. CLI, REST API, web console and an MCP server (so LLM agents can create and query their own branches) all use the same API.
- Single node or cluster. A Raft cluster of VMs, with optional ProxySQL routing so applications keep one address.
Web Console

Install
Requirements: Ubuntu 24.04 LTS or 26.04 LTS, and a ZFS pool (the zfsutils-linux package is installed as a dependency).
curl -fsSL https://apt.db-branch.com/db-branch.gpg | sudo tee /usr/share/keyrings/db-branch.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/db-branch.gpg] https://apt.db-branch.com stable main" | sudo tee /etc/apt/sources.list.d/db-branch.list
sudo apt update && sudo apt install db-branch
sudo db-branch init --pool <zpool>The repository signing key fingerprint is 3F404C4E5D49FA653F8385692C6E89E341D4D7A5. db-branch init prints the initial admin password once.
(注:更多技术实现细节与完整 API 文档请查阅原项目 README)