Skip to content

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

PlanetScale 12 min read Case study mediumAdept

How we migrate TBs from Heroku without logical replication

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. Version 2.0 fixes failures seen on large migrations. Bucardo's single-transaction initial copy restarted from zero after any interruption, so the migrator now drops secondary indexes before the copy and rebuilds them in parallel afterwards, raising throughput from about 60 to nearly 300 GB/h. It also disables transaction_timeout on Bucardo's connections, sets TCP keepalives so silently dropped long-lived connections fail within about a minute, and tunes host TCP buffers. A discovery CLI and the Liftoff assessment flag tables without primary keys, incompatible extensions and sizing before the migration starts.

Related posts

  • The growing pains of database architecture

    Figma mediumAdept

    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. Candidate tables were picked by measuring average active sessions from pg_stat_activity sampling and by tracing ActiveRecord queries into Snowflake to find isolated table groups. Migration used logical replication, with destination indexes dropped and rebuilt to cut initial copy from weeks to hours. Cutover went through a two-phase PgBouncer split, a brief pause with query cancellation, LSN-based sync checks, and reverse replication for rollback, keeping availability impact under a minute.

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

    ClickHouse mediumAdept

    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.

  • Breaking up a monolith: How we’re unwinding a shared database at scale

    Datadog Engineering mediumAdept

    Datadog is splitting its large shared Postgres database into independently owned instances through a three-phase plan: logical separation into per-domain private schemas with explicit ACLs, access reduction so only owning teams query their tables directly, and physical separation onto managed OrgStore instances. Domain boundaries came from clustering Database Monitoring query samples and validating them with 30+ teams. Inter-domain foreign keys were replaced with CDC or Postgres replication. A homegrown PG Proxy lets teams migrate at their own pace and makes cutover a dynamic config change, with write downtime under five seconds and reverse replication kept for rollback. The platform investments that made this feasible, the Rapid service framework, OrgStore and PG Proxy, are presented as prerequisites, and each phase has concrete progress metrics.

  • Leveraging Change Data Capture For Database Migrations At Scale

    Squarespace Engineering mediumAdept

    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. A reverse changefeed into a separate Kafka queue gave a rollback path to Postgres, and a homegrown diffing tool validated data before cutting over via a proxy. Snapshots reached about 60k rows/s and most systems were over 99.99% fresh at cutover, though some needed brief write pauses. Foreign-key failures across independent per-table writers, including cyclic constraints CRDB can't defer, were handled by disabling constraints during the isolated migration and restoring them before cutover.

  • How we migrated Clera’s 500 GB production database to ClickHouse Managed Postgres overnight

    ClickHouse mediumAdept

    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. The vendor choice followed a replay of their real workload (hot reads, point lookups, background analytics) on Supabase, Neon, PlanetScale and ClickHouse, plus sysbench TPC-C at 8–128 threads. Local NVMe storage beat network-attached storage, with 16–42% higher TPS than PlanetScale out of the box, and CPU fell from days at 100% to 10–20%. The hard parts were extension portability, restoring triggers, rebuilding indexes, resequencing tables, and doing parity checks before cutover.

The quest for software engineering knowledge.

Look:
Layout: