13 comments

[ 0.25 ms ] story [ 5.1 ms ] thread
This is interesting. Does it hook into Postgres and MySQL’s MVCC?
Postgres 18 has file_copy_method = clone for this, is that used underneath or did you implement your own own?
This is at the file system level. It says it uses the ZFS. Also, this is for MySQL as well, not just Postgres.
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
Database Lab is a great project, and since it's also ZFS-based, it's good validation that the approach works. My motivation was that most database branching tools seem to be built around Postgres, and I wanted something that works with MySQL too.
Is it possible to merge changes from a clone/branch back to the "official copy"?
Right now, branches are meant to be disposable: you can snapshot and restore, but there's no way to merge changes back into the source. I'd like to try it someday, but there are real challenges to solve, conflict resolution being the main one.
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...

cursor.execute("SET file_copy_method = 'clone'") cursor.execute( f'CREATE DATABASE "{target}" TEMPLATE "{source}" STRATEGY FILE_COPY' )

Works like a charm. Claude can set it all up for you in 20m, including branch tags and management/gc scripts. It is very familiar with this pattern and uses it well. Clones are fast and cheap, and you can basically forget about it all once it’s set up.