跳到正文
Hacker News:AI 熱帖·· 6 天前AI 評分56

db-branch 透過 ZFS 為 AI 智能體及 CI 數秒建立 MySQL 和 PostgreSQL 分支

Show HN: db-branch – database branches in seconds for AI agents and CI, via ZFS

AI 導讀

db-branch 利用 ZFS 的寫入時複製機制,為 AI 智能體及 CI 在數秒內建立 MySQL 和 PostgreSQL 資料庫分支,並可建立、刪除及重設分支。核心分支引擎和叢集功能免費開源,並支援分支快照還原及 ProxySQL SQL 路由;逐條查詢記錄與還原、企業用戶管理、SSO 和稽核則規劃為商業模組。每個分支都會增加資料庫程序的記憶體用量,大量寫入亦會增加磁碟空間需求。

正文

Image 1Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Show HN: db-branch – database branches in seconds for AI agents and CI, via ZFS (github.com/db-branch) 23 points by nu_nu115 hours ago | hide | past | favorite | 5 comments help Image 2pjm33140 minutes ago | next[–] So nice to have a way to get cheap db clones, I just set up this at work recently to do the same thing https://postgres.ai/docs/database-lab reply Image 3rzzzt24 minutes ago | prev | next[–] Is it possible to merge changes from a clone/branch back to the "official copy"? reply Image 4t0mas882 hours ago | prev | next[–] Postgres 18 has file_copy_method = clone for this, is that used underneath or did you implement your own own? reply Image 5n_u2 hours ago | prev | next[–] This is interesting. Does it hook into Postgres and MySQL’s MVCC? reply Image 6nu_nu115 hours ago | prev[–] Hey HN! I've read HN for years but this is my first post. db-branch uses ZFS copy-on-write to create, destroy, and reset MySQL and PostgreSQL clones in seconds, even for terabyte-scale databases. It's self-hosted and doesn't depend on any cloud vendor. Background Per-PR preview environments are common now, but the database is usually still a shared one. PlanetScale, Neon, and Aurora's fast clone solved this with Git-like branching, even for huge datasets: cut a branch in an instant, throw it away when you're done. The catch is that these are managed services tied to specific cloud vendors. Cost can be a barrier, fully air-gapped (on-prem) environments have constraints, and sometimes you just want the same workflow on your laptop. db-branch is meant for those cases. There's one more use case I care about: letting an AI agent such as Claude Code freely experiment with SQL against a database that looks like real data. 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. Being a disposable DB sandbox for AI agents is one of the goals of this project. Architecture Storage and processes: Using ZFS snapshot/clone, db-branch instantly creates a dataset from a snapshot of a cleanly shut down MySQL/PostgreSQL instance, then starts a process for it using a systemd template unit, switching ports per branch. Each branch runs as its own independent DB process. Dynamic routing: ProxySQL sits in front of the branch processes, so clients don't have to change port numbers. Branches are routed by connecting user or by a query comment (/db_branch=.../). This works for PostgreSQL as well as MySQL, using ProxySQL 3.x's PostgreSQL protocol support. Clustering: db-branch clusters are built with Raft and ZFS send/recv, and routing inside the cluster is also done by ProxySQL. Limitations and trade-offs - How the base snapshot is taken: For consistency, snapshots are taken from a cleanly shut down DB. This doesn't mean stopping your production DB. The idea is to stop a read replica and snapshot that, or to use an instance restored from a regular dump/backup as the base. - 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. Even so, if you run dozens of branches at the same time, you need to plan the host's RAM accordingly. - Heavy writes still cost disk: CoW only shares blocks that haven't been modified, so a branch that writes a lot consumes that much space. Features - Create and destroy MySQL and PostgreSQL branches - Take snapshots of a branch as save points, and restore from them - Upgrade verification for MySQL / PostgreSQL (upgrade version feature) - SQL routing via ProxySQL - Cluster setup - [Commercial module] Recording of executed queries and restore to any point (Lite Plan / History Module) Try it You can try it on a local Mac or Windows machine using Multipass: https://github.com/db-branch/db-branch#evaluate-locally-maco... Monetization and license To keep the project sustainable, the core branching engine and the clustering feature are released as fully open source, free of charge. More advanced features, namely the per-query recording and restore (History Module), plus enterprise user management, SSO, and auditing, are planned as modules of a commercial plan. Only some of these are available so far, and you can use them for a one-month trial period. (Whispering: if you're only playing around in the local Multipass environment, you can just tear down the VM and recreate it every month and keep using it basically forever... shhh ) reply Image 7 Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact Search:

來源:Hacker News:AI 熱帖 · news.ycombinator.com