---
title: "Making large Postgres migrations practical: 1TB in 2 hours with PeerDB"
description: "PeerDB migrated a 1TB, 3.6-billion-row Postgres table in about 1 hour 50 minutes with 8 threads, compared with 8 hours 40 minutes for native logical replication and 17 hours for pg_dump/pg_restore."
url: "https://swe.quest/articles/making-large-postgres-migrations-practical-1tb-in-2-hours-with-peerdb-cc7872fe91229eda"
canonical: "https://clickhouse.com/blog/practical-postgres-migrations-at-scale-peerdb"
source: "ClickHouse"
published: "2026-02-19"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 13
tags: ["postgres","replication","schema-migrations","performance","data-pipelines"]
---

# Making large Postgres migrations practical: 1TB in 2 hours with PeerDB

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-02-19, 13 min read, Deep dive. Original: [https://clickhouse.com/blog/practical-postgres-migrations-at-scale-peerdb](https://clickhouse.com/blog/practical-postgres-migrations-at-scale-peerdb)

## Summary

PeerDB migrated a 1TB, 3.6-billion-row Postgres table in about 1 hour 50 minutes with 8 threads, compared with 8 hours 40 minutes for native logical replication and 17 hours for pg\_dump/pg\_restore. The speedup comes from parallel snapshotting. A consistent snapshot is exported via pg\_export\_snapshot, the table is split into CTID ranges, and each range is streamed with binary COPY, with per-partition retries and progress visibility. Past a certain level of parallelism the source RDS network bandwidth becomes the limit, so 16 threads were no faster than 8 at 1TB. For CDC, PeerDB keeps the replication slot consumed independently of destination writes. It also reconstructs unchanged TOAST columns from batch caches and MERGE against the target, so REPLICA IDENTITY FULL is not needed.

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)
- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Data pipelines](https://swe.quest/tags/data-pipelines.md) (Data & databases)

## Prerequisites

- PostgreSQL logical replication ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- change data capture
- Postgres TOAST ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- COPY protocol

## Keywords

PeerDB, pg\_dump, pg\_restore, CTID, TOAST, pgoutput, ClickHouse, AWS RDS

## Related posts

- [How we migrate TBs from Heroku without logical replication](https://swe.quest/articles/how-we-migrate-tbs-from-heroku-without-logical-replication-e0568c616a878849.md): PlanetScale · 2026-11-11 · Medium · 12 min read · PostgreSQL, Schema migrations, Replication, Networking
  PlanetScale's open-source Heroku Migrator moves multi-terabyte Postgres databases off Heroku standard plans, which lack WAL access and logical replication, by using Bucardo trigger-based replication: triggers record changes in delta tables, a one-time COPY loads existing data, and a worker replays the backlog before a controlled switchover with verification.
- [The growing pains of database architecture](https://swe.quest/articles/the-growing-pains-of-database-architecture-9202c659b7981acc.md): Figma · 2023-04-04 · Medium · 12 min read · PostgreSQL, Schema migrations, Scaling, Replication, Databases
  Facing ~3x annual database traffic growth and 65% peak CPU on a single Amazon RDS Postgres instance, Figma chose vertical partitioning (moving groups of tables to their own databases) over horizontal sharding, NewSQL, or self-hosting.
- [Leveraging Change Data Capture For Database Migrations At Scale](https://swe.quest/articles/leveraging-change-data-capture-for-database-migrations-at-scale-c10095cde295b15f.md): Squarespace Engineering · 2025-05-13 · Medium · 6 min read · Schema migrations, Event-driven architecture, PostgreSQL, Distributed databases, Stream processing
  Squarespace migrated many PostgreSQL databases to CockroachDB without write downtime by streaming changes through a CDC pipeline: pgoutput logical decoding feeds per-table Debezium connectors into Kafka (Avro), and per-table Apache Beam pipelines on Dataflow upsert batched events into CRDB with checkpointing and backpressure.
- [How we migrated Clera’s 500 GB production database to ClickHouse Managed Postgres overnight](https://swe.quest/articles/how-we-migrated-clera-s-500-gb-production-database-to-clickhouse-managed-f4ed327a88d71cd7.md): ClickHouse · 2026-10-08 · Medium · 8 min read · PostgreSQL, Databases, Performance engineering, Schema migrations, Storage systems
  Clera moved a 500 GB, 500+ table production Postgres database from the EU to the US overnight onto ClickHouse Managed Postgres, with production traffic still running, using two parallel ClickPipes pipelines.
- [Postgres on NVMe: performance and the convergence of transactions and analytics](https://swe.quest/articles/postgres-on-nvme-performance-and-the-convergence-of-transactions-and-analytics-6553677f279f656e.md): ClickHouse · 2026-09-21 · Medium · 8 min read · PostgreSQL, Performance engineering, Storage systems, Replication, Analytics & OLAP
  Running Postgres on local NVMe instead of gp3 EBS gave 9.2× more throughput (16,030 vs 1,734 TPS) and UPDATE latency of 4.0 ms vs 36.9 ms in a pgbench benchmark with a 482 GiB dataset about 30× larger than RAM.

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)
