---
title: "How to Keep Staging in Sync with Production in Postgres"
description: "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."
url: "https://swe.quest/articles/how-to-keep-staging-in-sync-with-production-in-postgres-2a3ed8d4d274df22"
canonical: "https://neon.com/blog/how-to-keep-staging-in-sync-with-production-in-postgres"
source: "Neon"
published: "2025-12-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["postgres","replication","privacy","testing"]
---

# How to Keep Staging in Sync with Production in Postgres

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-12-23, 5 min read, How-to. Original: [https://neon.com/blog/how-to-keep-staging-in-sync-with-production-in-postgres](https://neon.com/blog/how-to-keep-staging-in-sync-with-production-in-postgres)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Privacy](https://swe.quest/tags/privacy.md) (Security)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- staging environments

## Keywords

Neon, pg\_dump, pg\_restore, logical replication, AWS DMS, database branching, copy-on-write

## Related posts

- [Why Your Staging Database Never Matches Production](https://swe.quest/articles/why-your-staging-database-never-matches-production-0082e7428bf22c68.md): Neon · 2025-12-12 · Medium · 8 min read · PostgreSQL, Testing, Schema migrations, Privacy
  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).
- [How to Handle PII in Staging Databases Without Losing Realistic Data](https://swe.quest/articles/how-to-handle-pii-in-staging-databases-without-losing-realistic-data-41c0818c53e7c05e.md): Neon · 2025-11-17 · Medium · 11 min read · Privacy, PostgreSQL, Testing, Databases
  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).
- [Practical Guide to Database Branching](https://swe.quest/articles/practical-guide-to-database-branching-8aa2f63325bcfecb.md): Neon · 2025-12-04 · Medium · 9 min read · PostgreSQL, Databases, CI/CD, Schema migrations, Testing
  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.
- [Neon Twin: Automate Partial Data Dumps with Postgres and GitHub Actions](https://swe.quest/articles/neon-twin-automate-partial-data-dumps-with-postgres-and-github-actions-0e318b92e17657ec.md): Neon · 2025-02-10 · Medium · 7 min read · PostgreSQL, CI/CD, Testing
  A scheduled GitHub Actions workflow can keep a Neon "Twin" refreshed with a partial copy of a production Postgres database.
- [Branching With or Without PII: The Future of Environments](https://swe.quest/articles/branching-with-or-without-pii-the-future-of-environments-9928f840495df503.md): Neon · 2025-11-11 · Easy · 12 min read · PostgreSQL, Privacy, Databases, CI/CD
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
