Postgres for Ephemeral Environments: A Method to Keep Data Persistent
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.
Related posts
- Practical Guide to Database Branching
Neon mediumAdept
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.
- 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.
- 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.
- Beyond Docker Compose: An Alternative for Deploying Postgres for Testing
Neon mediumAdept
Docker Compose with the official Postgres image gives each developer and CI run an isolated test database, but it struggles with production-like seed data, leftover state between runs, and RAM/CPU overhead. The usual workarounds each cost something: custom data images get bloated, seeding containers slow test startup, shared staging databases cause contention, and tmpfs uses a lot of RAM. Neon's alternative is copy-on-write database branches, which share storage with a parent database and get their own compute, so tests start against prepopulated data in a clean, isolated state. Local containers remain the better fit for offline work, full local control and light testing needs, while branches suit parallel CI and complex test scenarios.
- Fullstack preview environments using Neon and Qovery
Neon mediumAdept
Each Qovery preview environment can get its own isolated Postgres database by using a Qovery lifecycle job that creates a copy-on-write Neon branch on the environment's Start event and deletes it on Delete. A Docker image bundles the Neon CLI and two shell scripts. create-branch.sh creates a branch named after QOVERY_ENVIRONMENT_NAME and writes direct and pooled connection strings to /qovery-output/qovery-output.json, so other services receive them as environment variables. delete-branch.sh looks up the branch ID through the Neon API and deletes it. This sidesteps the conflicts of a shared preview database and the slow provisioning, stale seed scripts and privacy issues of copying production data.