Practical Guide to Database Branching
Neon's copy-on-write storage makes Postgres database branches instant and cheap: each branch shares the parent's base data, gets its own autoscaling compute that scales to zero, and can be created from any point within the history retention window. Recommended workflows include a protected production branch whose child branches get new credentials automatically, staging and per-developer or per-pull-request branches that are periodically reset from the parent, and anonymized branches (beta) as the parent when data contains PII. Point-in-time branches support recovering dropped tables, debugging bad migrations and audits without rolling back production. Ephemeral branches should be deleted promptly, and the restore window (6 hours on the Free plan, 1 day on paid plans) can be shortened to cut storage costs.
Related posts
- Branching Postgres databases with the Neon API
Neon mediumAdept
Neon branches are copy-on-write clones of a Postgres database that can be created and deleted through the Neon API, giving CI pipelines an isolated copy of production data for end-to-end tests. Two experimental GitHub Actions, neondatabase/create-branch-action and neondatabase/delete-branch-action, wrap the API. A sample pull-request workflow creates a branch from a parent branch, runs the test steps, then deletes the branch. The actions were beta at the time and still being hardened for production use.
- Postgres for Ephemeral Environments: A Method to Keep Data Persistent
Neon easyNovice
Neon branches, which are copy-on-write clones of a Postgres database, can provide pre-seeded databases for ephemeral PR environments. Because a branch references the parent's data pages instead of copying them, it is created in seconds whatever the dataset size. Persistent dev and test environments suffer from configuration drift, seed-data maintenance, shared-environment conflicts and idle cost. Ephemeral environments fix most of this but still stall on loading seed data into each database. The proposed workflow keeps sanitized seed data in one main branch and has GitHub Actions create a child branch per pull request, reset it from the parent when needed and delete it on merge, with scale-to-zero limiting cost.
- Branching With or Without PII: The Future of Environments
Neon easyNovice
Neon branches can now be created with anonymized data: schema and data are copied from a parent such as production, then masked with the PostgreSQL Anonymizer extension using per-column rules (dummy emails, names, phone numbers, random values) while foreign keys and constraints stay intact. Branching itself relies on separated compute and storage, WAL stored by Safekeepers with LSN markers for point-in-time branches, and copy-on-write layers in the Pageserver, with per-branch compute scaling to zero. The post argues this replaces manually maintained dev, preview, CI and staging databases. The beta uses static masking that runs once at branch creation, leaves the parent untouched, and keeps rules branch-specific.
- Adopting Neon branching in CI/CD pipelines: a practical story by Shepherd
Neon mediumAdept
Shepherd, an insurtech startup that moved its Alchemist pricing engine from SQLite to Postgres, uses Neon's copy-on-write database branches to give every pull request an ephemeral test database. GitHub Actions call the Neon API to create a branch when a PR opens and delete it on merge. Changes then flow from per-developer and per-PR branches to staging and production, with Render pre-deploy commands applying migrations tracked in a dedicated timestamped table. The team credits branching with removing the cost and effort of keeping test instances synced with production, and notes that scale-to-zero means it no longer pays for idle databases.
- Using Neon branching for instant Point in time recovery
Neon mediumAdept
Neon's copy-on-write branching can restore a Postgres database to an earlier point in time by creating a branch from a timestamp or LSN within the retained WAL history window (seven days by default). Creating the branch from the console gives you a new compute endpoint and so a new connection string. To keep the existing connection string, a TypeScript script using the Neon API client creates an endpoint-less branch at the target timestamp, reassigns the existing compute endpoint to it, and sets it as the primary branch. Afterward, rename the old branch and delete its data to avoid storage charges.