NCP Account Migration: Choosing a Short Maintenance Window Over Zero Downtime and Proving It in Rehearsal
Why I moved PostgreSQL and Redis between NCP accounts with dump-and-restore during a short maintenance window, and how a rehearsal with production data validated the plan before a cutover with about 13 minutes of user impact.
On this page
- Introduction
- This Was Different From a Blue-Green Deployment That Only Replaces the App
- Comparing Three Migration Approaches
- Deciding Based on Actual Data Size and Usage Hours
- When Writes Resumed Mattered More Than the Downtime
- Reading the Production Database Once, Then Testing Copies
- Verifying the Data Separately From the Copy Command’s Success
- Checking Whether Requests From the New Application Reached Production
- Problems the Rehearsal Actually Exposed
- Results of the Actual Cutover on October 23
- Conclusion
Introduction
Preparing servers and deploying the app in a new account does not finish a migration. Users’ messages and login state also have to reach the new environment.
In October 2026, I moved WITIM, an internal company groupware, to a new NCP account. Part 1 covered rebuilding the infrastructure and deployment path with Terraform and NKS. What remained was the data. Messages, attendance records, and approval records were stored in PostgreSQL, while login sessions and some usage information remained in Redis. Servers could be recreated, but this data had to be moved with its existing state intact.
I first considered whether a zero-downtime cutover was possible. But before I took over the migration, an earlier attempt to move the login service to the new account and then roll it back had left several days of login and audit records missing from the production database. Important account information had not changed, and the original backup was still available. Even so, the incident showed that routing traffic back does not automatically restore the data.
The previous owner’s plan also included PostgreSQL logical replication. Replication can reduce downtime, but it introduces new connections and replication state into a running database. I had only recently taken over the infrastructure and first needed to establish how production was actually configured.
So before asking how much downtime I could cut, I asked when writes should stop, and what conditions must pass to keep the data from diverging. This post compares three migration approaches and explains why I chose to move the data in one pass during a short maintenance window. It then covers what I checked while rehearsing that approach with production data, and how the actual cutover went.
This Was Different From a Blue-Green Deployment That Only Replaces the App
In a typical blue-green deployment, both apps use the same database. Wherever traffic goes, the data stays in one place. This migration required moving the database itself to another NCP account, along with the app.
Existing app → Existing DBNew app → New DBIf both environments accept writes at the same time, user records accumulate in separate databases. Returning to the old account would still leave the records created in the new database to deal with. Running apps in both environments is possible if writes are restricted to one database, but changing the data store ultimately still requires synchronization and control over writes.
Having seen the actual gap in the login service’s data, I made avoiding any interval in which both databases independently accept writes a principle of the cutover. It was not enough to check that the connection path worked; I also had to consider whether writes made in the new account could be brought back to the old one.
Comparing Three Migration Approaches
I compared dump-and-restore, logical replication, and moving the app and database separately, weighing the downtime each could save against the work each would add.
| Approach | What it offers | Additional burden in this environment |
|---|---|---|
| Dump, restore, then cut over | A straightforward procedure and a clear cutover boundary | Service writes must stop during the final data copy |
| Logical replication, then cut over | A shorter pause in writes | Requires cross-account SSH tunnels, replication slots, sequence synchronization, a DDL freeze, and replication state management |
| Move the app first, then the database | The app cutover itself can happen without downtime | Requires network access from the new app to the existing DB and Redis, followed by another cutover to move the database |
Logical replication was the most direct way to reduce downtime. After synchronizing the full dataset and continuously following changes in the production database, only the final differences would need checking on cutover day. Earlier migration records also showed that tables had actually been synchronized.
But keeping table contents in sync does not complete a migration. Sequences and DDL changes require separate handling, and replication connections, slots, and lag need ongoing monitoring. Replication slots that are not cleaned up can also increase WAL retention. The real question was whether saving maintenance time justified introducing all this for a connection that would be removed after the migration.
I also considered moving the app first and the database later. Sharing the existing database with the new app could make the first traffic cutover close to zero downtime. However, it would require additional network connectivity between the two accounts and broader access to the database and Redis. Moving the data stores would then require another cutover.
This approach is useful when the app changes substantially or the database is large enough to justify splitting the work. Here, I was moving the same app image, and the dataset was small. A zero-downtime app cutover and a zero-downtime account migration were different things.
Deciding Based on Actual Data Size and Usage Hours
To judge whether that burden was worth it, I first needed to know how much data there actually was. These were the measurements at the time.
| Item checked | Measurement at the time |
|---|---|
| PostgreSQL actual data | About 623 MB |
| PostgreSQL dump file | 46.5 MB |
| Database restore | 43 seconds, all 285 tables matched (from a preliminary test on October 7) |
| Redis | About 9,000 keys |
| Messages from 03:00–08:00 | 0–18 per hour (over the preceding four weeks) |
At this size, stopping and restarting the app and checking functionality in the new environment were likely to take longer than copying the data itself. The service already had a maintenance mode, and changing the origin address in the Cloudflare proxy could direct traffic to the new load balancer.
When choosing the maintenance window, I did not assume that nobody would use the service in the early morning. I checked message counts over the preceding four weeks to find hours that were actually quieter.
At the planning stage, I estimated a write pause of about 15–20 minutes for dump-and-restore and about 3–5 minutes for logical replication. These were estimates made when selecting the approach. Choosing logical replication would not eliminate the time needed to restart the app, migrate Redis, or check functionality. The difference therefore affected only part of the overall maintenance window.
I ultimately decided to build and validate the new environment in advance, then transfer only the final data during maintenance. I also kept PostgreSQL at the existing version, 15.15, rather than upgrading to 17 during the account migration. Changing more at once would add more variables to investigate if something failed.
For Redis, I initially planned to transfer only login tokens. After classifying the production keys, I found that not everything was cache data that could be recreated. Some information existed only in Redis, including usage statistics that had not yet been written to the database and mobile login state. Deciding key by key what could be discarded would itself risk omissions, so I decided to move everything.
Redis also needed a separate migration regardless of the approach chosen for PostgreSQL. Reducing the PostgreSQL write pause through logical replication would not make the entire service cutover zero downtime. At roughly 9,000 keys, I judged a full copy to be practical.
When Writes Resumed Mattered More Than the Downtime
With the approach decided, I fixed the order of when to copy data and which checks had to pass before accepting writes again.
The important distinction in this sequence was between displaying a maintenance page and actually stopping writes. Even with external requests blocked, internal workers or scheduled jobs could continue writing to the database, changing the source data after the final dump. I therefore stopped the app and jobs before copying the final data.
Until user writes begin in the new environment, returning to the existing environment remains an option. But once records have accumulated in the new database, changing DNS back is not enough to recover. A separate decision is needed about how to handle the writes that have already occurred. I therefore defined the cutover by the point when writes resume after the data comparison and new service checks pass, rather than by the moment the address changes.
The original plan allowed 1–2 hours for maintenance because checks of the new environment were included on cutover day. Moving those checks into a rehearsal the day before would let the actual cutover focus on stopping writes, copying the final data, validating it, and switching traffic. What remained was to confirm in advance that this procedure worked with real data.
Reading the Production Database Once, Then Testing Copies
The rehearsal had two goals: measuring how long the maintenance window would really take, and finding problems before encountering them for the first time on cutover day. Knowing the restore duration alone was not enough to predict the total downtime. Starting the new application, checking database connections and chat and file features, and switching traffic would also take time. I did not want to be investigating a PostgreSQL extension error or a wrong connection address for the first time while users could not access the service.
Because the rehearsal used real data, it could not be allowed to affect production. The restored database contained real user information, and the copied configuration included secrets for accessing push notifications, email, and file storage. So I started by protecting the production database.
I first checked that automated backups were working, then took a single read-only dump of the production database and used that file for every subsequent restore and test. There was no need to repeatedly connect to the production database or touch its schema. The diagram below shows the path the dump file took and what the test environment could reach.
I did not set up VPC peering between the old and new accounts. The managed databases were accessible only from the NKS node address ranges, so I ran the dump and restore in temporary pods inside the respective clusters and transferred the file with kubectl cp. The operator’s computer served as the place to inspect intermediate files and verification results. Given the small data volume, this was simpler than establishing a permanent connection between accounts.
I first restored the file into a local Docker database with its network access blocked and checked it there, then restored the same file into the new account’s database. The purpose of this sequence was to avoid touching the production database again, even if repeated tests failed.
I also added checks to the scripts to prevent restoring to the wrong place. They prohibited selecting the source cluster as a restore target and compared the Kubernetes API server address, PostgreSQL server identifier, and Redis run_id to check whether the source and target were the same. I kept a separate kubeconfig file for each cluster. Even if the new environment’s configuration was wrong, there was no direct network path to the production database.
Verifying the Data Separately From the Copy Command’s Success
I passed PostgreSQL connection details to the temporary pod through a Kubernetes Secret rather than putting them in the command line. The source session used the read-only option:
PGOPTIONS='-c default_transaction_read_only=on'I created the dump with pg_dump -Fc. Because the application account in the managed database could not install extensions, I prepared the extensions in the target database beforehand and excluded their installation entries from the dump’s table of contents. I also did not carry the old database’s ownership and permissions over unchanged to the new account. The restore ran in a single transaction with pg_restore -1 --exit-on-error, so a failure halfway through could not leave only part of the restore applied.
I did not judge completion by the exit code alone. I compared the table lists and the exact row count of every table in the source and new databases, and a mismatch prevented the next step from running. All 285 tables matched during the rehearsal. With roughly 500,000 rows, the cost of actual count(*) queries rather than statistical row estimates was manageable.
Equal row counts do not, of course, prove that every record has identical contents. I therefore combined several checks: restoring the same dump, stopping immediately on any restore error, and comparing table and row counts. The process did not depend on a success message from any single step.
For Redis, I moved every key as decided earlier. I used DUMP and RESTORE with the same Redis version, carried over the remaining expiration time with PTTL, and compared key counts after the copy.
Checking Whether Requests From the New Application Reached Production
Before opening the new environment to users, I changed only /etc/hosts on the operator’s MacBook. Only that computer connected to the new load balancer; real users’ requests continued to go to the old NKS cluster. I used only an operations team account and a personal test account, checking login, chat, file uploads, and administration features in a conversation containing just those two accounts.
Changing the entry address did not redirect every connection. External services copied through environment variables, such as file storage, could still point to actual production resources. I therefore limited the test files and accounts and removed the files after checking them. Leaving DNS unchanged did not eliminate every possible external effect.
Workers needed separate isolation. Unlike the web application, they could begin processing scheduled jobs stored in Redis as soon as they started. To keep a worker with the same Secrets as production from sending duplicate push notifications or emails, I blocked external communication with a Cilium NetworkPolicy, allowing only the internal communication needed for testing, such as access to the new database and Redis.
I did not assume that applying a policy meant isolation was working. Before starting the worker, I verified from the pod that external communication was actually blocked, then checked whether the worker could use its internal database and Redis normally.
During the rehearsal, the worker ran for 19 minutes and processed about 650 jobs across 13 queues, with no database or Redis errors. Since external calls were blocked, however, those results could not prove successful push notification or email delivery. I left external delivery as an item to check after the actual cutover.
Problems the Rehearsal Actually Exposed
The rehearsal revealed three unexpected problems. Each could easily have gone unnoticed if I had only checked whether the app was running or whether a command succeeded. For each, I describe which test exposed it and how and when I addressed it.
Messages From the New Web Application Were Published to the Old Centrifugo
When I connected to the web application in the new account and tested chat, messages were being published to the old production Centrifugo rather than the new cluster. The copied CENTRIFUGO_API_URL still pointed to the old service’s public address.
The new web application started normally, and login worked. But real-time messages are published by the web server through a separate Centrifugo API. Even when the browser connects to the new web application, where the web server sends messages depends on its configuration. Checking that route separately exposed the incorrectly copied setting.
Had I cut over in that state, the web application and database would have used the new account while message publishing continued to target the old one. The new cluster’s real-time connections and the actual message route would not have aligned, leaving chat delays or delivery errors to investigate on cutover day.
I changed the setting to Centrifugo’s internal address in the new cluster during the rehearsal, and on cutover day I checked again that messages appeared immediately. I also added an item to the rehearsal checklist: check the actual connection targets of internal dependencies, as well as whether the service is running.
PostgreSQL Extension Schemas Caused the First Restore to Fail
The first PostgreSQL restore failed. The vector and pg_stat_statements extensions were installed in the NCP managed database’s cdb_admin schema rather than the schema the script expected. Preparing the extensions in the target database beforehand was not enough if the restore could not handle that schema difference.
The initial script assumed that the rest of the restore would proceed normally once extension installation statements were excluded. But in managed PostgreSQL, the accounts and schemas available for installing extensions can differ from a typical environment. Preparing the same PostgreSQL major version did not mean the managed service’s internal configuration would be identical.
I modified the existing restore runner to read extension schema information from the dump file and handle it accordingly. After the change, I restored the data again and checked that row counts matched across all 285 tables. I confirmed that the original acceptance checks passed again, rather than merely that the error had disappeared.
Had I encountered this error for the first time during the production cutover, I would have had to investigate and retry the restore while writes were stopped. It confirmed that migration scripts need to be tested with real dumps against the target managed database’s particular behavior, not just checked for correct syntax and options.
Redis Still Had 699 Keys From an Earlier Rehearsal After Overwriting
For Redis, the copy command succeeded, but the source and target key counts did not match. The target still contained 699 keys created during an earlier rehearsal.
redis-import --replace overwrites keys with the same name, but does not delete keys that exist only in the target. I had read replace, which means replacing conflicting keys, as making the entire target identical to the source. Repeated rehearsals could keep leaving old test keys in the target.
Redis held more than cache data. It also contained login sessions, mobile session pointers, and usage statistics whose state needed to match at the time of restoration. I found the discrepancy because I had added a key-count comparison after the copy.
Although I discovered this during the rehearsal, the copy tool was not fully fixed until after the production cutover. On cutover day, I manually compared and removed the leftover keys, ultimately verifying that 9,587 keys matched. Afterward, I changed the runner from “overwrite existing keys” to “clear the target, then restore.” Not everything was found and fixed within the rehearsal: on cutover day I relied on manual verification, and the tool was improved afterward.
The three problems had different causes: an old service address left in an environment variable, extension schemas in managed PostgreSQL, and a wrong assumption about Redis’s replace behavior. All of them could have been missed without comparing actual results. After the rehearsal, I added checks to the cutover-day procedure: whether the new web application uses the new real-time server, whether restoration on the managed database passes all the way through row-count comparison, and whether Redis holds any keys that do not exist in the source.
Results of the Actual Cutover on October 23
After the rehearsal, I returned the new application to standby. The actual cutover followed the order decided earlier.
Oct 22 23:59 Stop writes in the existing environmentOct 23 00:01–00:05 Final PostgreSQL and Redis transferOct 23 00:06 Start apps in the new environmentOct 23 00:12 Finish switching 5 Cloudflare entry points| Check | Result |
|---|---|
| PostgreSQL | 285 tables and 495,192 rows matched |
| Redis | 9,587 keys matched |
| User impact | About 13 minutes |
| Web requests in the first hour after cutover | 5,518 requests, zero 5xx responses |
| Worker jobs during the same period | 1,926 succeeded, zero restarts |
I also checked that users remained logged in on web, desktop, and mobile, and that real-time chat, files, and push notifications worked. Data transfer had taken about two minutes in the rehearsal, but the actual cutover also included stopping and starting applications and checking their features. The data copy time and the total user impact should be read separately.
The cutover finished within the maintenance range estimated when choosing the approach. That was possible because I had criteria for comparing the source and target data and had decided in advance which stage to stop at if a problem occurred. Rechecking the deployment path and monitoring against the new account after the cutover is covered in Part 1.
Conclusion
Measuring the data size and restore time first is what let me choose a short maintenance window with dump-and-restore. Rather than managing temporary networking and replication state to save a few more minutes, stopping writes and moving the data with a pre-validated procedure fit the operating conditions at the time.
Choosing a simple approach did not make the preparation light. The rehearsal prevented restores to the wrong cluster, isolated the copied application from production, and exposed problems with PostgreSQL extension schemas, the Centrifugo address, and leftover Redis keys. Encountering any of them for the first time during maintenance could have prolonged the cutover or required another data comparison.
The point is not that dump-and-restore is always better than logical replication. It is that I measured the service’s scale and operating conditions, chose a level of complexity that fit them, and backed that choice with a verification procedure I could repeat in the same order.
Series: Part 1 · Moving the Production Environment to a New Account · Part 2 · Choosing the Migration Approach and Proving It in Rehearsal
Comments