Skip to content

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

Neon 5 min read How-to mediumAdept

How to Keep Staging in Sync with Production in Postgres

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.

Assumes: PostgreSQL basicsstaging environments

Related posts

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

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

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

  • Neon Twin: Automate Partial Data Dumps with Postgres and GitHub Actions

    Neon mediumAdept

    A scheduled GitHub Actions workflow can keep a Neon "Twin" refreshed with a partial copy of a production Postgres database. It installs a pinned Postgres version via apt, dumps the schema with pg_dump, extracts row subsets to CSV with psql \copy, then drops and recreates the target schema and restores it with pg_restore. When subsetting related tables, the selection queries must keep foreign keys intact and the restore must load parent tables first. Partial dumps can also reduce PII exposure by leaving out sensitive tables and columns.

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

The quest for software engineering knowledge.

Look:
Layout: