PostgreSQLDev & Eng
Content type: Concept
7 min read
How a 40 TB PostgreSQL Migration Became a Single-Night Cutover
- Reading
- 7 min
A case study published by Stormatics details the migration of a PostgreSQL database of more than 40 TB to an EDB Postgres cluster, with cutover completed in a single early morning after months of preparation.
Stormatics, a consultancy specialized in PostgreSQL, published on December 1, 2026, the account of a production migration of more than 40 TB of data to an EDB Postgres cluster. The client is a payments company subject to financial regulation, which alone already changes the rules of the game. The text, authored by Umair Shahid and published on Planet PostgreSQL, is the continuation of a post published in September about the deliberate postponement of the cutover date.
The cutover itself began at 2 a.m. local time, and by morning the application was already back online, with all post-migration validations confirmed in writing by the client's team. The news here isn't the migration technique, which PostgreSQL has offered for years via logical replication. It's what Stormatics calls a de-risking playbook: the sequence of decisions that turns a 40 TB operation into something boring enough to succeed.
The size of the largest tables dictates the calendar
The database had two tables that together accounted for a large share of the total volume: one of 8.6 TB and another of 4.5 TB. The rest of the database synced in days; these two took weeks, and the cutover could only happen after both were fully caught up with the source. A dump/restore was ruled out due to particularities of the client's environment.
The lesson Shahid draws from this is direct: the schedule for a large migration isn't planned around the total volume, but around the single largest table. A 40 TB database made up of a thousand tables of 40 GB each is a completely different project from a database where two tables concentrate a third of the data. Identifying these giant tables on the first day of planning is what determines whether the proposed date is realistic.
In this case, the cutover date was postponed four times, each postponement motivated by something learned in a previous rehearsal. For those who work with critical data, this is the difference between cutting on the date and cutting when the data is ready to be cut.
Why postponing came cheap, and why that only works with replication
The reason postponing four times cost almost nothing is the chosen architecture. Data flowed through logical replication while the old system kept serving production normally, with no perceptible impact on the business. Each extra week of waiting didn't consume downtime: it bought more synchronization, one more rehearsal, more confidence.
In short: with dump and restore, waiting doesn't help at all, because the copy only happens during the downtime window. With replication, the copy runs in the background and the cutover window only needs to cover the last stretch of pending changes. Time starts working in favor of whoever is migrating, not against them.
In the last week before the cutover, the remaining lag on the largest tables amounted to about a week's worth of changes, something around 12 million rows. That volume is small enough to be absorbed within a planned window, and that's exactly what turns a 40 TB migration into a single-night cutover.
Parallelism on the giant tables, and the details that make the difference
A single replication stream copying an 8.6 TB table is slow: the initial copy runs as a single job, and on a table of that size this can take days. Stormatics' solution was to split the backfill of the largest tables into parallel workers, each responsible for a slice, with separate tracking and checkpoints every few days to compare progress against the plan.
Three technical precautions appear in the account as decisive for anyone looking to reproduce this strategy:
- WAL on the source: while the long copy runs, the replication slot retains write-ahead log until the subscriber confirms receipt. On a high-traffic primary, this accumulates quickly, and disk space needs to be sized for the total duration of the copy, not for a normal day of operation.
max_slot_wal_keep_sizerequires attention: this parameter protects the primary from filling up its disk, but if the slot exceeds the limit in the middle of the migration, it gets invalidated and that table's sync starts over from scratch.- Measure instead of estimate: in recent PostgreSQL versions,
pg_stat_progress_copyshows the progress of each table's initial copy, whilepg_stat_subscriptionandpg_replication_slotsindicate each subscriber's lag. Real numbers replace intuition in checkpoint meetings.
There's also a point that easily slips through the runbook: logical replication moves table data, but in current PostgreSQL versions, sequence values aren't synchronized automatically. The cutover script needs an explicit step to adjust sequences on the destination, in addition to manually applying any schema change made during the migration window.
The calendar outside the database is also part of the plan
Being a regulated company, the client had to notify the regulator several business days in advance before any production cutover. This requirement turns a small delay into a big problem: if the largest table finishes syncing one day later than expected, the company doesn't lose a day, it loses the entire window, because the notice was already sent for a date that won't be met, and the next opportunity is a month away.
The practical recommendation is to incorporate this external calendar into the plan from the start: notification deadlines, change-freeze windows, and the weekends on which the business can actually tolerate a stoppage. Each candidate date should be treated as a target the data needs to earn, not as a promise locked in beforehand.
The night of the cutover, and the week that follows
Since the heavy lifting had already been done in the previous weeks, the night itself followed the runbook without surprises: the application stopped writing, the last changes were drained, the new cluster took over, and the application team ran its tests against it. Shahid sums up the philosophy behind this in a line he often repeats to his own team:
I always tell my team – strategy trumps valor.
Umair Shahid, Stormatics
In this account, the migration only ends when the new system runs under real load and stays healthy. That's why the client and Stormatics set aside a week of intensive monitoring, what the company calls hypercare, covering replication health on each standby, WAL archiving to ensure backup and point-in-time recovery, query performance against the old system's baseline, CPU, memory and disk usage under production load, and the state of the failover manager and the cluster as a whole.
This vigilance paid off concretely: shortly after the cutover, one of the standbys showed replication lag. Because someone was watching exactly that indicator, the problem was caught early, fixed, and the standby became synchronized again with no effect on production. Without this dedicated monitoring, the first sign of the lag could have been a failover to an outdated replica.
What this means for those working with critical data in Brazil
The case reinforces something any experienced DBA already knows in practice, but which rarely appears documented in this level of detail: migrating a large database isn't an event, it's a risk-reduction process measured in weeks of rehearsal, not hours of cutover. Brazilian teams dealing with regulated databases, whether under rules from Banco Central (Brazil's central bank), ANPD (Brazil's data protection authority), or sectors such as healthcare and payments, will find in the external calendar described by Stormatics a direct parallel to the notification deadlines and change windows that also exist here.
Stormatics has also announced, for December 16, 2026, a webinar led by Semab Tariq, the company's delivery manager, on migrating to PostgreSQL 18 using logical replication, covering the same type of rehearsal, very large databases, sequences, and the hypercare week after the cutover. For anyone planning a migration of similar size, it's worth following this complementary material alongside this account.
Left open in the original text is the detail of how Stormatics specifically monitored the post-cutover standby lag (which queries or alerts fired), which would be useful for anyone wanting to reproduce the same level of observability. The account also doesn't go into cost figures for the operation, only the time invested in rehearsals and postponements.
Translated from the Brazilian Portuguese original · Read the original
PostgreSQL 19 brings WAIT FOR LSN as an alternative to synchronous replication
New command shifts to the application the decision of whether to wait for a replica, promising to end the stalled commits of traditional synchronous replication.





