Moving the database to a new host (or a new major version)? A 12-point checklist so the site doesn't look 'up' while every write fails

2026-12-01来源 dev.toEnglish

Uptime monitoring from outside your own infrastructure that alerts you the minute your site goes down — upordown.online

Database moves go well in staging and then surprise you in production, because the app has more connections than you listed: a web pool, a worker pool, a reporting user, a cron job with a hardcoded host, a forgotten BI tool, a serverless function with its own secret. During the window it is common for reads to work and writes to fail, which is exactly the shape of "the site looks up, and nobody can do anything".

This is the checklist I want next to the runbook.

Before the cut

1. Inventory every client, not every "service". Grep for the hostname, the old IP, the connection string env vars, and the secrets manager keys. Include one-off scripts, psql in cron, migrations that run in CI against production, and serverless functions that only run on a schedule. Write the list down. Anything not on it will be the thing that breaks at 02:00.

2. Measure the real cutover window. How long to promote a replica, how long for DNS or a proxy to move, how long for clients to drop idle connections (many pools hold a connection for minutes). Your announced window should be that number plus a margin, not the time the failover command itself takes.

3. Decide read-only vs hard cut. A period where the old primary is read-only and the app refuses writes with a clear error is kinder than a hard close that surfaces as 500s. If you cannot do read-only, have a maintenance page for the paths that write.

4. Check versions, extensions and parameters. A major upgrade is a different project from a host move. Extensions (uuid-ossp, pg_stat_statements, citext, PostGIS), search_path, time zone, locale, max_connections, and disk size on the new host have all caused "it's up but every query fails" cutovers. Dump SELECT extname, extversion FROM pg_extension; and the relevant GUCs from production, and compare.

5. Rehearse with a copy of production traffic if you can. At least: run the app's boot, a login, a write, a background job, and a migration against a restored copy of the new host. Time the restore and the promote.

6. Plan how secrets change, and when processes load them. A new hostname in a secrets manager does nothing until every process is restarted or can reload. Some pools resolve DNS only at start; they will hold the old IP after a clean DNS cut. Schedule the bounce, or use a proxy (PgBouncer, RDS proxy) whose name stays stable.

During the cut

7. Stop writers in a controlled order. Pause schedulers and workers first, then put the app into a mode that doesn't take payments or sign-ups, then promote or cut. The other order (promote first, then hunt for leftover writers on the old primary) is how you split-brain.

8. Cut, then verify a write from the public path. Not psql from a bastion. Sign up, place a test order, or update a record through the same URL customers use, and read it back. Confirm it landed on the new host (inet_server_addr(), a canary row, a new sequence range).

9. Watch connection errors and idle-in-transaction, not just CPU. After the cut you should see old connections drop and new ones appear on the new host. If the web pool is fine and the worker pool is still on the old host, you will ship the homepage and fail every email, invoice or webhook.

A cutover can leave the homepage green and the money path dead, especially if a page is cached or served from a replica. upordown.online can watch a path that has to write — login, signup, or a synthetic checkout — from outside, so a database move that only half-completed is an alert, not a quiet pile of 500s on POST.

10. Keep the old primary up, read-only, until you are sure. Do not destroy it in the same change window. If you have to revert, you want it there. Block writes so a forgotten client cannot silently add data you will never see again.

After the cut

11. Hunt leftover clients for at least one business cycle. The weekly report, the Monday billing job, the partner feed at 05:00: they will be the ones still pointing at the old name. Log connections on the old host; anything that still arrives is a missed item from step 1.

12. Leave monitors pointing at the public app, and add one check that writes (or at least that talks to the primary). A SELECT 1 against a replica, or a homepage check, will stay green through a failed primary cut. A synthetic that logs in or hits an endpoint which does INSERT ... RETURNING will not.

Other traps that show up on the night

  • Certificate and SSL mode. The new host has a different hostname; clients with sslmode=verify-full will refuse to connect until the CA and the name match.
  • search_path and default privileges. A restore can look complete while the app user cannot see the tables it used to own.
  • Sequence drift if you failed back and forth. Check them before you reopen writes.
  • Connection limits. The new instance, or the proxy in front of it, may have a lower max_connections than the sum of your pools.

Do the inventory and the rehearsal even if the move "is just a promote". The promote is the easy part.

Related reading

What was the leftover client that showed up after your last database move — a cron job, a worker, or something you didn't know existed?

原文:https://www.a8q9.cn/en/article/moving-the-database-to-a-new-host-or-a-new-major-version-a-12-point-checklist-so-85e980.html

相关文章