DatabaseLesson 12 of 16

Managed Databases

Beyond Azure SQL Database, Azure offers SQL Managed Instance for near-full SQL Server compatibility, plus fully managed MySQL and PostgreSQL services for open-source workloads.

Overview

Three managed database offerings cover most workload migration scenarios:

ServiceEngineBest For
SQL Managed Instance (SQL MI)SQL Server (near 100% compat)Lift-and-shift SQL Server with full features
Azure DB for MySQLMySQL 5.7 / 8.0PHP/LAMP stacks, WordPress, Drupal
Azure DB for PostgreSQLPostgreSQL 11-16Django, Rails, GIS (PostGIS), analytics

SQL Managed Instance

SQL MI is a fully managed SQL Server instance — think SQL Server deployed in a VNet, managed by Azure, with near 100% feature compatibility including SQL Agent, CLR, linked servers, cross-database queries, and service broker.

SQL MI vs Azure SQL Database

FeatureAzure SQL DatabaseSQL Managed Instance
SQL Server agentLimitedFull support
Cross-database queriesNoYes
CLR / Linked serversNoYes
Network isolationPublic endpoint or PEDeployed inside VNet
On-prem migrationModerate effortMinimal changes
CostLowerHigher (starts ~$200/mo)
Best forNew apps, modern workloadsSQL Server migration, enterprise apps

Azure Database for MySQL

Fully managed MySQL with automatic backups, patching, and HA. The Flexible Server deployment is the recommended option (replaces Single Server which is being retired).

Azure CLI — MySQL Flexible Server
# Create MySQL Flexible Server
az mysql flexible-server create \
  --resource-group rg-database \
  --name myapp-mysql-flex \
  --location eastus \
  --admin-user mysqladmin \
  --admin-password "P@ssw0rd2024!" \
  --sku-name Standard_D2ds_v4 \
  --tier GeneralPurpose \
  --version 8.0

# Create database
az mysql flexible-server db create \
  --resource-group rg-database \
  --server-name myapp-mysql-flex \
  --database-name appdb

# Open firewall (add client IP)
az mysql flexible-server firewall-rule create \
  --resource-group rg-database \
  --name myapp-mysql-flex \
  --rule-name ClientIP \
  --start-ip-address 203.0.113.10 \
  --end-ip-address 203.0.113.10

# Connection string (MySQL)
# Server=myapp-mysql-flex.mysql.database.azure.com;
# Database=appdb;Uid=mysqladmin;Pwd=P@ssw0rd2024!;SslMode=Required;

Azure Database for PostgreSQL

Fully managed PostgreSQL with Flexible Server (standard deployment) and extensions support (PostGIS, pg_vector, etc.). Ideal for Python (Django/SQLAlchemy), Ruby on Rails, and Node.js apps.

Azure CLI — PostgreSQL Flexible Server
# Create PostgreSQL Flexible Server
az postgres flexible-server create \
  --resource-group rg-database \
  --name myapp-pg-flex \
  --location eastus \
  --admin-user pgadmin \
  --admin-password "P@ssw0rd2024!" \
  --sku-name Standard_D2ds_v4 \
  --tier GeneralPurpose \
  --version 16

# Create database
az postgres flexible-server db create \
  --resource-group rg-database \
  --server-name myapp-pg-flex \
  --database-name appdb

# Connect (psql)
psql -h myapp-pg-flex.postgres.database.azure.com \
  -U pgadmin -d appdb

# Enable PostGIS extension
# In psql: CREATE EXTENSION postgis;

Decision Guide

Which Managed DB Should I Use?
  • Migrating existing SQL Server (enterprise features needed) → SQL Managed Instance
  • New app, standard SQL, no DBA team → Azure SQL Database
  • PHP/LAMP app, CMS (WordPress/Drupal) → Azure DB for MySQL
  • Python/Django, Rails, GIS, JSON-heavy, analytics → Azure DB for PostgreSQL
  • Global scale, schema flexibility, multi-model → Cosmos DB

Hands-on

  1. Create an Azure DB for MySQL Flexible Server and connect with MySQL Workbench.
  2. Create a PostgreSQL Flexible Server, connect via psql, and create a table.
  3. Enable the pg_vector extension on PostgreSQL for AI embedding storage.
  4. Compare the connection strings and discuss how apps point to managed DBs.
  5. Review the Metrics panel for each DB — examine active connections and query time.

Debugging Scenario

Issue: MySQL app throws "SSL connection error" after migrating to Azure DB for MySQL.

Interview Questions

Beginner

What is the difference between SQL MI and Azure SQL Database?

SQL MI is a full SQL Server instance inside your VNet — supports CLR, SQL Agent, linked servers, cross-database queries. Azure SQL Database is a modern PaaS database — lower cost, simpler, lacks some SQL Server-specific features.

Scenario-based

You're migrating a legacy SQL Server 2014 app that uses SQL Agent jobs and linked servers.

Use SQL Managed Instance — it has near 100% feature compatibility with SQL Server. Azure SQL Database would require significant application refactoring to remove SQL Agent and linked server dependencies.

Django app currently running on a self-hosted PostgreSQL VM. Team doesn't want to manage the DB server.

Migrate to Azure DB for PostgreSQL Flexible Server. It supports the same PG protocol and extensions. Update the connection string; Django ORM works without changes.

Summary

SQL Managed Instance offers the closest lift-and-shift path for SQL Server workloads. Azure DB for MySQL and PostgreSQL provide fully managed open-source database options without vendor lock-in. All three include automatic backups, patching, HA, and built-in monitoring.