keepcalculator

06 Numbers and Powers

Test a Database Migration Before Production Cutover

Card No. 06·57257 · Updated · Standard formula, shown below

Testing a database migration before a production cutover helps reveal data loss, schema incompatibilities, performance problems, and application errors while you still have time to respond. You’ll need a representative, protected copy of the source data, a staging environment, the migration procedure, and a rollback or recovery plan.

What You’ll Need

  • Access to the source and target database systems, plus the migration tool or scripts.
  • A staging environment configured as closely as practical to production, including database versions, extensions, settings, and application dependencies.
  • A recent, consistent backup or sanitized production-like dataset. Protect sensitive data and follow your organization’s data-handling rules.
  • Representative application code, configuration, and a way to run automated tests and inspect logs and database metrics.
  • Written acceptance criteria, an estimated maintenance or cutover window, and documented recovery steps.

Step-by-Step

  1. Define what success means. Record the source and target database versions, migration scope, expected downtime, and critical user journeys. Set measurable checks: required tables and indexes exist, row counts or business totals reconcile, constraints hold, and application tests pass. Identify acceptable performance thresholds and who can approve the cutover. Do not rely on “the migration command finished” as the only success criterion.
  2. Inspect the migration before running it. Review scripts, generated SQL, and tool settings. Look for destructive operations such as dropping or renaming columns, changing types, rebuilding indexes, or rewriting large tables. Check whether the migration is repeatable or safe to resume after interruption. Confirm how it handles nulls, defaults, character sets, time zones, sequences or identity values, and database-specific features. Resolve unsupported objects and dependencies before the rehearsal.
  3. Prepare and verify a representative test copy. Restore a recent backup into an isolated staging system, or create a consistent snapshot using an approved method. If data must be sanitized, verify that sanitization does not remove patterns needed to test relationships, unusual values, large records, or workload volume. Keep production credentials and endpoints out of staging configuration. Confirm the copy’s timestamp and record baseline counts, key aggregates, schema details, and database size.
  4. Rehearse the migration using the intended procedure. Follow the planned order, commands, configuration, and application compatibility steps. Record start and finish times, warnings, manual interventions, and resource use. Include prerequisite changes and any required writes to the target; do not silently skip steps that operators would need during cutover. If the process is supposed to run online, test it under realistic concurrent reads and writes. Otherwise, test the intended write-freeze or maintenance procedure.
  5. Validate the migrated data and schema. Compare source and target table or partition counts, important totals, and selected records. Check primary and foreign keys, unique constraints, nullability, indexes, views, triggers, stored procedures, and permissions where applicable. Use deterministic checksums only when their handling of ordering, types, and encoding is understood. Investigate discrepancies rather than assuming small differences are harmless; expected changes should be documented and reconciled.
  6. Test the application against the target. Point a staging build at the migrated database and exercise critical workflows: reads, inserts, updates, deletes, reporting, scheduled jobs, and integrations. Test boundary cases such as empty values, maximum-sized records, and old data formats. Review application and database logs for errors, slow queries, lock waits, and connection failures. Run automated tests, then perform focused manual checks on workflows that tests do not cover.
  7. Measure performance and operational behavior. Compare representative queries and workloads with the baseline. Check query plans, index use, CPU, memory, storage, replication lag if relevant, and connection-pool behavior. Test backups and confirm that the target can be restored, not merely that a backup job reports success. Verify monitoring and alerts, access controls, and the ability to pause or stop a migration safely.
  8. Test recovery and repeat the rehearsal. Follow the written rollback or forward-recovery plan in staging. A database rollback may not be safe after new writes or incompatible schema changes, so establish how writes will be captured, reconciled, or paused. Confirm the authoritative database at each stage and how applications will be redirected back. Fix issues, refresh the test copy if needed, and rerun the complete procedure until it meets the acceptance criteria within the planned window.
  9. Make a cutover decision and monitor closely. Publish a checklist with owners, commands, stop conditions, communication steps, and a go/no-go decision point. Cut over only after required approvals and a fresh, verified backup or recovery point. During the change, validate the same critical checks before reopening writes or traffic. Monitor errors, latency, data consistency, and capacity; if a stop condition occurs, pause and follow the tested recovery plan rather than improvising.

Common Mistakes

  • Testing on a tiny or stale copy: It can hide long-running operations, unusual data, and production-scale performance problems.
  • Checking only row counts: Counts can match while values, relationships, permissions, or indexes are wrong. Combine structural, aggregate, and application checks.
  • Ignoring application compatibility: A schema can migrate successfully while deployed code expects columns or behavior that no longer exist. Test the actual release and transition sequence.
  • Assuming rollback is automatic: Reversing a schema change may not restore data or undo writes made after cutover. Test recovery with realistic changes.
  • Skipping concurrency and operational checks: Locks, replication lag, connection limits, and scheduled jobs can cause problems that a quiet one-off test will miss.

Tips

  • Keep a run log with exact commands, versions, timings, decisions, and observed results so another operator can repeat the rehearsal.
  • Use the same migration artifact and settings intended for production; avoid manually editing staging to make it pass.
  • Separate pre-cutover checks from post-cutover checks, and assign a person to verify each item.
  • Prefer a small, reversible test change first when practical, but do not treat it as a replacement for a full rehearsal.
  • Agree in advance on a time limit and concrete stop conditions, such as failed reconciliation, unexpected errors, or performance beyond the agreed threshold.

Troubleshooting

The migration fails partway through: Preserve logs and the staging database state. Check whether the tool applied the operation transactionally and whether it supports resuming. Do not blindly rerun scripts; inspect which changes completed, restore the test copy if necessary, and revise the recovery instructions.

Counts or values do not match: Check whether writes continued during the snapshot, whether filters or transformations were applied, and whether time zones, encoding, rounding, or default values changed. Compare affected records and reconcile against the defined source-of-truth point.

The application fails on the target: Use logs to identify missing objects, changed types, permissions, connection settings, or code that assumes a particular schema. Test compatible deployment ordering, such as adding a field before code begins using it, where the database and application support that approach.

Performance is unexpectedly poor: Confirm indexes and statistics, inspect slow queries and execution plans, and check resource limits, locks, and connection behavior. Repeat the test with representative load after changes; do not extrapolate from an idle staging system.

Recovery cannot restore the old service: Stop the rehearsal and update the plan before production. Determine whether the issue is a missing backup, incompatible application version, unaccounted-for writes, or an untested routing step. If the recovery path cannot be demonstrated, treat the migration as not ready.

Frequently Asked Questions

Can I test a migration without copying production data?
Yes, but use synthetic or sanitized data that preserves realistic sizes, relationships, and edge cases. A small hand-made dataset alone is rarely enough to assess performance or data-specific failures.

How many times should I rehearse the migration?
Repeat it until the documented procedure succeeds consistently, including validation and recovery, within the planned window. Rehearse again after meaningful changes to scripts, data, infrastructure, or application versions.

Should I test with production traffic?
Do not direct real production traffic to an unapproved test target. Use representative load in an isolated environment, or an approved shadow or read-only method that cannot affect production data.

Is a successful backup enough to make rollback safe?
No. Verify that the backup can be restored and decide how to handle writes made after the recovery point. A backup is one part of a recovery plan, not proof that rollback will be quick or lossless.

What if the target database uses a different engine?
Check feature and type differences carefully, including SQL behavior, indexes, constraints, collations, and transaction semantics. Test application queries and stored logic on the target engine, not only the data-transfer step.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →