---
title: "Neon Twin: Automate Partial Data Dumps with Postgres and GitHub Actions"
description: "A scheduled GitHub Actions workflow can keep a Neon \"Twin\" refreshed with a partial copy of a production Postgres database."
url: "https://swe.quest/articles/neon-twin-automate-partial-data-dumps-with-postgres-and-github-actions-0e318b92e17657ec"
canonical: "https://neon.com/blog/automate-partial-data-dumps-with-postgresql-and-github-actions"
source: "Neon"
published: "2025-02-10"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["postgres","ci-cd","testing"]
---

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

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-02-10, 7 min read, How-to. Original: [https://neon.com/blog/automate-partial-data-dumps-with-postgresql-and-github-actions](https://neon.com/blog/automate-partial-data-dumps-with-postgresql-and-github-actions)

## Summary

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.

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)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- GitHub Actions workflows ([easy posts on CI/CD](https://swe.quest/tags/ci-cd.md?difficulty=easy))
- pg\_dump and pg\_restore

## Keywords

Neon, GitHub Actions, pg\_dump, pg\_restore, psql

## Related posts

- [Neon Twin: Move Dev/Test/Staging to Neon, Keep Production on RDS](https://swe.quest/articles/neon-twin-move-dev-test-staging-to-neon-keep-production-on-rds-a26cd19df36ac332.md): Neon · 2024-07-24 · Medium · 7 min read · PostgreSQL, CI/CD, Databases
  A Neon Twin is a nightly-synced copy of an RDS Postgres production database kept in Neon for dev, test and staging, so teams get instant provisioning, branching and scale-to-zero without migrating production.
- [Neon Twin: How to deploy a change tested in Neon to prod in RDS](https://swe.quest/articles/neon-twin-how-to-deploy-a-change-tested-in-neon-to-prod-in-rds-09282f8f58bccb12.md): Neon · 2024-08-15 · Medium · 10 min read · Schema migrations, PostgreSQL, CI/CD, Deployment
  Schema changes tested on Neon database branches can be promoted to an AWS RDS production Postgres database through GitHub Actions that run when a pull request merges.
- [Branching Postgres databases with the Neon API](https://swe.quest/articles/branching-postgres-databases-with-the-neon-api-3faf0de941bc811a.md): Neon · 2022-12-07 · Medium · 3 min read · PostgreSQL, CI/CD, Testing
  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.
- [How to Keep Staging in Sync with Production in Postgres](https://swe.quest/articles/how-to-keep-staging-in-sync-with-production-in-postgres-2a3ed8d4d274df22.md): Neon · 2025-12-23 · Medium · 5 min read · PostgreSQL, Replication, Privacy, Testing
  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.
- [Postgres for Ephemeral Environments: A Method to Keep Data Persistent](https://swe.quest/articles/postgres-for-ephemeral-environments-a-method-to-keep-data-persistent-5ef8547c6782b2cb.md): Neon · 2025-01-07 · Easy · 7 min read · PostgreSQL, Deployment, CI/CD, Testing
  Neon branches, which are copy-on-write clones of a Postgres database, can provide pre-seeded databases for ephemeral PR environments.

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)
