Database Migration to Azure
Plan and execute a database migration using Azure Database Migration Service, and review common strategies for minimising downtime during a move to the cloud.
Database Migration to Azure is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Migrate Databases to Azure?
Migrating databases from on-premises to Azure delivers benefits including reduced operational overhead (no hardware management), built-in high availability and backups, and the ability to elastically scale compute and storage on demand. Organisations also migrate to satisfy cloud-first mandates, retire ageing data-centre hardware, or take advantage of advanced features like geo-replication and intelligent query tuning.
Migration Strategies Overview
Database migration typically follows one of two broad strategies. An offline migration takes the source database offline, copies data to the target, and then switches applications to the new endpoint — simple but requires a maintenance window. An online migration uses continuous data replication to keep the target in sync with the source while it is live, cutting over with minimal downtime measured in seconds or minutes.
Azure Database Migration Service
Azure Database Migration Service (DMS) is a fully managed tool that orchestrates database migrations from a wide range of sources — SQL Server, MySQL, PostgreSQL, MongoDB, Oracle, and more — to their corresponding Azure managed targets. DMS handles schema conversion, data movement, and replication, and reports migration status and errors in a single dashboard.
# Create a DMS instance
az dms create \
--location eastus \
--name myDMSinstance \
--resource-group myRG \
--sku-name Standard_1vCores \
--subnet /subscriptions/<sub-id>/resourceGroups/myRG/providers/Microsoft.Network/virtualNetworks/myVNet/subnets/mySubnetPre-Migration Assessment
Before migrating, run a pre-migration assessment to identify compatibility issues between the source database and the target Azure service. The Database Migration Assessment for SQL Server extension in Azure Data Studio scans stored procedures, triggers, and queries for features not supported in Azure SQL Database or SQL Managed Instance, giving you a prioritised list of items to fix before cutover.
SQL Server to Azure SQL Database
Migrating SQL Server to Azure SQL Database (single database) works well for applications with a single database and no instance-level features (like SQL Agent or cross-database queries). If the assessment reveals instance-level dependencies, Azure SQL Managed Instance is a near-100% compatible lift of the SQL Server engine into a PaaS container, preserving SQL Agent jobs, linked servers, and CLR objects.
Online Migration with Log Replay
Azure DMS uses Log Replay Service (LRS) for online SQL Server to Azure SQL Managed Instance migrations. LRS continuously reads transaction log backups from an Azure Blob Storage container and replays them on the target Managed Instance, keeping it in sync with the source. The final cutover is triggered manually and completes within seconds, minimising the maintenance window to nearly zero.
PostgreSQL to Azure Database for PostgreSQL
For moving PostgreSQL databases to Azure, DMS supports both offline (pg_dump/pg_restore) and online migration via logical replication. The source PostgreSQL server must have logical replication enabled (wal_level = logical) and the migration user must have replication privileges. DMS handles schema migration, initial full load, and change data capture until the final cutover.
# Enable logical replication on source PostgreSQL
# In postgresql.conf:
wal_level = logical
max_replication_slots = 5
max_wal_senders = 5MySQL to Azure Database for MySQL
DMS migrates MySQL databases to Azure Database for MySQL Flexible Server using the MySQL binary log for continuous replication. The source MySQL instance must have binlog_format = ROW and binary logging enabled. The migration wizard in the Azure portal guides you through connecting source and target, selecting databases, and monitoring migration progress and lag before cutover.
# Verify binary logging on source MySQL server
SHOW VARIABLES LIKE 'log_bin';
SHOW VARIABLES LIKE 'binlog_format';Minimising Downtime During Cutover
The key to a low-downtime migration is completing the bulk initial load well in advance, then letting change data capture run until replication lag drops to near zero. At that point you: stop writes to the source, wait for the last changes to drain to the target, update the application connection string, and start writes on the new target. Careful DNS TTL management and blue-green switching can reduce impact further.
Post-Migration Validation
After cutover, validate the migration by comparing row counts between source and target tables, running key application queries to verify data correctness, and checking that all stored procedures, views, and functions return expected results. Monitor the target for query performance regressions by comparing execution plans, and update statistics and rebuild indexes on the target to ensure optimal performance from day one.
-- Compare row counts across all tables
SELECT TABLE_NAME, TABLE_ROWS
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'myDatabase'
ORDER BY TABLE_NAME;Using Azure Migrate for DB Discovery
Azure Migrate provides a database discovery and assessment capability alongside its server assessment features. The Azure Migrate appliance scans your on-premises environment to inventory SQL Server instances, estimate their Azure-equivalent sizing and cost, and flag compatibility issues. This makes it the logical starting point before using DMS for the actual migration execution.
Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: Azure Database Migration Service orchestrates migrations from many source engines, online migrations use change data capture to minimise downtime during cutover, and a pre-migration assessment identifies compatibility issues before you begin. Next up we explore Azure Identity and Microsoft Entra ID.
Frequently asked questions
Is the “Database Migration to Azure” lesson free?
Yes — the full text of “Database Migration to Azure” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Database Migration to Azure”?
Plan and execute a database migration using Azure Database Migration Service, and review common strategies for minimising downtime during a move to the cloud. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Database Migration to Azure” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Azure SQL Database
- Azure Cosmos DB: Global NoSQL
- Azure Database for Open-Source Engines
- Database Migration to Azure