GLOSSARY

What is copy-on-write (CoW)?

Copy-on-write (CoW) is a storage optimization where a database branch shares data pages with the parent database. Pages are only duplicated when they are modified. This enables instant branch creation at near-zero initial storage cost — a 1 TB database branches in seconds and uses 0 MB until changes are made.

HOW IT WORKS

How copy-on-write works

In a traditional database copy, every data page is duplicated: the full table data, indexes, and metadata are written to new storage. For a 500 GB database, this means writing 500 GB — which takes hours and doubles your storage bill.

Copy-on-write changes this fundamentally. When a branch is created, the system creates a new page table (essentially a pointer map) that references the same physical pages as the parent. No data is copied. The branch immediately has access to all the parent's data through shared references.

When a write occurs on the branch — say, an UPDATE to a row — only the 8 KB page containing that row is copied to branch-specific storage. All other pages continue to be shared. This is why storage costs scale with changes, not with database size.

The parent database is completely unaware of branches. Its pages are never modified by branch operations. When a branch is deleted, only the branch-specific pages are freed — shared pages remain for the parent.

Neon implements CoW at the storage layer using their custom pageserver. Ardent uses this same technology to branch any Postgres database, regardless of where it's hosted.

WHY IT MATTERS

Why copy-on-write matters

Copy-on-write makes database branching economically viable. Without CoW, creating 10 copies of a 200 GB database means 2 TB of storage — roughly $200/month on AWS. With CoW, those same 10 branches start at 0 MB and only grow as changes are made. A typical testing branch that modifies a few thousand rows might use 50 MB.

This cost structure enables workflows that were previously impractical:

Branch per CI run — create a fresh database copy for every CI pipeline execution. At $0.01 per branch, it's negligible.

Branch per developer — every engineer gets their own copy of production to test against. No shared staging environment conflicts.

Branch per AI agent session — give Claude Code or Cursor a disposable copy for every task. Delete it when done.

EXAMPLE

copy-on-write in practice

-- Traditional copy: duplicate everything
-- pg_dump + pg_restore = full database copied, 45+ minutes
-- Storage: full duplicate of entire database

-- Copy-on-write branch via Ardent: share everything, copy on change
$ ardent branch create my-branch
✓ Branch created in 5.4s
postgres://branch-cow01.db.tryardent.com:5432/mydb
-- Storage used: 0 MB (shares all pages with parent)

-- Modify 10,000 rows on the branch:
UPDATE orders SET status = 'archived'
WHERE created_at < '2024-01-01';
-- 10,000 rows modified
-- Only the changed pages are stored on the branch
-- Parent database: completely unaffected

-- Delete the branch:
$ ardent branch delete my-branch
-- Changed pages freed, shared pages untouched
RELATED CONCEPTS

Related terms

Database Branching
Database Sandbox
Ephemeral Environments
FAQ

Frequently asked questions

What is copy-on-write in databases?

Copy-on-write is a storage optimization where branches share data pages with the parent. Pages are only copied when modified, enabling instant branch creation at near-zero cost.

How much storage does a CoW branch use?

A CoW branch initially uses 0 MB. Storage grows only as you modify data. Modifying 10,000 rows on a 500 GB database stores only those changed pages, not the full 500 GB.

Try copy-on-write with Ardent

Create isolated database branches in under 6 seconds. No risk to production.

Read the docsBook a demo