Skip to content

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

Neon 11 min read How-to mediumAdept

How to Handle PII in Staging Databases Without Losing Realistic Data

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.

Related posts

  • Create Environments with Masked Production Data Using Neon Branches

    Neon mediumAdept

    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.

  • 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 Keep Staging in Sync with Production in Postgres

    Neon mediumAdept

    Postgres staging environments drift from production, and the traditional fixes each fall short. pg_dump/pg_restore gives a clean copy but takes staging offline and runs for hours on large databases. Logical replication and AWS DMS keep rows in sync but not schema or configuration, and they add load to production. All three copy PII as-is. Database branching with copy-on-write storage, as in Neon, makes staging an instantly resettable branch of production, and an intermediate anonymized branch masks sensitive columns before staging and dev branches are derived from it.

  • Why Your Staging Database Never Matches Production

    Neon mediumAdept

    Staging databases drift from production continuously in three ways: data drift (stale dumps, sequence values that diverge so the same ID points to different records), schema drift (hotfixes, skipped migrations, mismatched indexes and extensions causing query plan divergence), and transformation drift (anonymization that breaks uniqueness, referential integrity and determinism). Scheduled pg_dump refreshes only cap staleness while adding lock windows and slow restores at scale, and logical replication doesn't carry DDL. The proposed fix is ephemeral copy-on-write database branches created at test time, inheriting production schema, data and sequences, with optional per-column masking, as offered by Neon.

  • pg_redact: Content-aware PII redaction with Jev, enforced in Postgres

    Neon mediumAdept

    Column-level masking in Postgres can't redact PII buried in free text, and regex alone can't tell an SSN from an invoice number. pg_redact generates candidate spans with regex and capitalization rules, asks TypeSafe's Jev model to label each one (name, email, phone, address, id_number, none) with calibrated probabilities, and stores spans above 0.5 confidence as JSONB next to the message. A plpgsql redact() function compares each span's sensitivity rank against the caller's clearance, replacing longest spans first. Because labels and enforcement are decoupled, role clearances and sensitivity levels can change without reclassifying text.

The quest for software engineering knowledge.

Look:
Layout: