Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 7 min read How-to mediumAdept

Create Environments with Masked Production Data Using Neon Branches

Neon combines copy-on-write database branches with the PostgreSQL Anonymizer (anon) extension to create production-like non-prod environments without exposing PII. The workflow branches from production, applies column-level static masking rules via SECURITY LABEL declarations and faker functions (anon.fake, anon.partial, anon.noise), runs anon.anonymize_database(), and then uses the anonymized branch as the base for per-PR previews, CI, local dev and contractor access. Masking preserves schema, types and referential integrity, and the anonymization step can be automated with a GitHub Action on pull request creation.

Related posts

  • 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.

  • How to Handle PII in Staging Databases Without Losing Realistic Data

    Neon mediumAdept

    Four common ways to get realistic but PII-safe staging data are compared, with code for each: manual CSV export plus Python anonymization scripts, Faker-based masking libraries with deterministic seeding to preserve referential integrity, fully synthetic data generators, and replication into staging with SQL masking views or the PostgreSQL Anonymizer extension (declarative security labels, dynamic masking, anonymized dumps, k-anonymity checks). Scripts and libraries break silently when schemas add new PII columns, synthetic data loses production's skew and messiness, and replication with masking is robust but operationally heavy. The recommended approach is Neon's copy-on-write branches combined with user-defined masking rules, so a masked staging copy of production can be created or refreshed cheaply.

  • 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.

  • A database for every preview environment using Neon, GitHub Actions, and Vercel

    Neon mediumAdept

    Neon's copy-on-write branching can give every pull request its own production-like Postgres database, avoiding the bottlenecks of shared staging or shared preview databases. Branches are isolated, are created in about a second regardless of database size, and bill only for unique data. A GitHub Actions pipeline creates a Neon branch per PR, runs Prisma migrations against it, deploys a Vercel preview wired to that branch, and comments the URLs on the PR. Merging applies migrations to the primary branch, deploys to production and deletes the preview branch.

  • 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.

The quest for software engineering knowledge.

Look:
Layout: