Why AI coding agents want throwaway databases: copy-on-write branches and scale to zero
Google previewed AlloyDB Express for coding agents and Lakebase Postgres went GA on Google Cloud. Why agents want databases they can throw away, how copy-on-write branching and scale to zero work, and what Postgres 18 can already do: a published test cloned 6 GB in 0.21 s instead of 67 s.
Two launches in the same week point at the same idea. On November 5, Google Cloud previewed AlloyDB Express, a Postgres offering “designed specifically for developers and AI coding agents”. Google says a database is ready in under two seconds, pauses after 15 minutes without queries, and costs $0.00 for compute while paused. Three days earlier, Databricks made Lakebase Postgres generally available on Google Cloud: serverless Postgres whose compute “shuts off when idle”, with “zero-copy branches of production data in seconds”.
Both are built for a new kind of user. Here’s why that user wants databases it can throw away, how the two tricks behind it work, and how much of it plain Postgres 18 can already do.
Agents treat databases like temp files
Picture a coding agent fixing a bug. It writes a migration, runs the test suite, maybe drops a table by mistake, and tries again. It needs a real database it is allowed to break, and it rarely does one task: it runs several in parallel, retries, and walks away when it’s done. That’s the life cycle of a temp file: create, use, delete.
This is not hypothetical. When Databricks agreed to acquire Neon in May 2025, its press release said that “over 80 percent of the databases provisioned on Neon were created automatically by AI agents rather than by humans”, and that Neon spins up a “fully isolated Postgres instance in 500 milliseconds or less”.
For that to work, two things have to be cheap: making a copy of a database, and keeping a database that nobody is using. The first is copy-on-write branching, the second is scale to zero.
Four ways to copy a Postgres database
pg_dump | psqlturns every row into SQL text, parses it back and rebuilds every index from scratch. Portable, and the slowest way to make a local copy.CREATE DATABASE new TEMPLATE appcopies inside the server. The default strategy,WAL_LOG, copies “block by block and each block will be separately written to the write-ahead log”, which the PostgreSQL manual calls the most efficient choice “in cases where the template database is small”. For a big template, every block is written twice.… STRATEGY FILE_COPYwrites only a small WAL record per tablespace, but “forces the system to perform a checkpoint both before and after the creation of the new database”, and still copies every file.- Don’t copy at all: let the filesystem share the blocks.
All three CREATE DATABASE variants share one rule from the manual: “no other sessions can be connected to the template database while it is being copied”. Keep a dedicated template that nothing else uses.
How much faster is not copying?
Radim Marek published a test in boringSQL, “Instant database clones with PostgreSQL 18” (December 2025): a database of about 6 GB with 50 million rows, on XFS.
| Strategy (Postgres 18, ~6 GB, XFS) | Time |
|---|---|
CREATE DATABASE … TEMPLATE (default WAL_LOG) |
67.0 s |
STRATEGY FILE_COPY with file_copy_method = clone |
0.212 s |
That’s about 316× faster. And the size barely matters: the developer of Pigsty, an open-source Postgres distribution, reports cloning a 120 GB database “in about 200 milliseconds” and a 797 GB one in “roughly 569 milliseconds” on NVMe SSDs.
These come from different machines, so read them as orders of magnitude, not a benchmark.
Copy-on-write: copy the list, not the data
A file on disk is a list of blocks. A copy-on-write clone (Linux calls it a reflink) is a second list pointing at the same blocks. The ioctl_ficlone(2) man page describes files “sharing physical storage”, which is “faster than making a separate physical copy”; when one of them is written, “the filesystem must ensure that the changes remain private to the file being written”, which is “commonly referred to as copy on write”.
Postgres 18 can ask for this. The new setting file_copy_method accepts COPY (the default) or CLONE, which uses copy_file_range() on Linux and FreeBSD (copyfile on macOS), “giving the kernel the opportunity to share disk blocks”. copy_file_range(2) is exactly that hook: it “gives filesystems an opportunity to implement copy acceleration techniques, such as the use of reflinks”.
SET file_copy_method = clone; -- per session
CREATE DATABASE test_42 TEMPLATE app STRATEGY FILE_COPY;
-- ... run the migration, the tests ...
DROP DATABASE test_42;
The filesystem has to cooperate. boringSQL’s checklist is “Linux with XFS or ZFS, macOS with APFS, or FreeBSD with ZFS”; on a standard filesystem “like ext4”, Postgres “reads every byte of the source file and writes it to a new location”. And if a database spans tablespaces on different mount points, “cloning will fall back to regular physical copy”.
Free until you write
A clone is only free while both sides are identical. In the same boringSQL test, updating 20 rows made the first 40 blocks diverge, 160 KB in total, because “any write to a shared page triggers a copy of that entire page”.
Now add how Postgres updates work. It never edits a row in place: the manual says “updates require new versions of rows to be added to tables. This can also require new index entries for each updated row.” So an update that touches one row on every page changes every page, and every changed block gets its own copy: your free clone quietly turns into a full copy. Branches are great for tests and short agent tasks; a branch that rewrites a large table is a full copy in slow motion.
Scale to zero: split compute from storage
The second trick is making idle databases free. In a normal server, Postgres and its data live in one box, so a stopped server is a server you can’t query. Neon, whose engine Lakebase Postgres runs on, splits the system into “two independent layers”: compute and storage. Storage keeps the WAL (safekeepers), turns it into pages (the pageserver) and keeps the durable history in object storage, while “compute nodes do not own durable state and can be replaced freely”.
That makes both tricks natural:
- Scale to zero: the compute can stop. Neon’s docs say a database “automatically scales to zero after 5 minutes” of inactivity and “reactivates automatically within a few hundred milliseconds”. AlloyDB Express pauses after 15 minutes and “wakes up automatically in seconds”.
- Branching: a new branch “points to an existing point in history and begins diverging from there using copy-on-write semantics”. Neon’s branching docs call it “a copy-on-write clone of your data”, and Databricks’ Lakebase docs add that “the size of your database has no impact on branch creation time”.
| Ready | Idle after | Wakes in | |
|---|---|---|---|
| AlloyDB Express (preview) | “under two seconds” | 15 min | “seconds” |
| Neon | “500 milliseconds or less” | 5 min | “a few hundred milliseconds” |
One billing detail from the Lakebase docs: “an expiring branch is billed only for the data that changes on it”, but a “permanent branch, one with no expiration, is billed for its full data size”. If an agent creates branches, give them an expiry.
What this means for your own tests
You don’t need a cloud service to get most of this:
- Load your fixtures once into a template database, and give every test or agent task its own
CREATE DATABASE … TEMPLATE, thenDROP DATABASEwhen it’s done. - On Postgres 18 with an XFS or ZFS data directory (APFS on a Mac), set
file_copy_method = cloneand useSTRATEGY FILE_COPY: a full copy in a fraction of a second, according to the published tests above. - Keep nothing connected to the template, keep branches short-lived, and expect writes, especially scattered updates, to cost real disk.
- For hosted agents, Neon, Lakebase and AlloyDB Express do the same at the storage layer, plus scale to zero for the copies nobody is using.
How long does your test suite wait for a database? I’m curious what the fastest setups out there look like.