Azure SQL Managed Instance
Complete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Deploying and Managing Azure SQL Managed Instance
Introduction: The Bridge Between On-Premises and Cloud
In the modern data landscape, organizations frequently face a challenging dilemma when moving to the cloud: they require the full compatibility and deep configuration capabilities of a traditional SQL Server instance, but they also want the automated maintenance, scaling, and high availability features of a platform-as-a-service (PaaS) offering. Azure SQL Managed Instance (MI) is designed specifically to fill this gap. It provides a near 100% compatibility with the latest SQL Server on-premises engine while removing the overhead of managing the underlying operating system, patching, and hardware lifecycle.
Understanding how to deploy and manage Azure SQL Managed Instance is a critical skill for data engineers and database administrators. By mastering this service, you gain the ability to "lift and shift" complex legacy applications that rely on features like cross-database queries, SQL Agent jobs, and CLR integration without needing to rewrite them. This lesson will guide you through the architecture, deployment strategies, networking requirements, and operational best practices necessary to run production-grade workloads on Azure SQL Managed Instance.
Understanding the Architecture of Azure SQL Managed Instance
At its core, Azure SQL Managed Instance is a collection of system and user databases hosted within a virtual network (VNet) in Azure. Unlike Azure SQL Database, which is a single-tenant or multi-tenant database service, a Managed Instance is essentially a dedicated instance of the SQL Server engine. This architecture allows it to support features that are typically unavailable in single-database PaaS models.
Key Architectural Characteristics
- Virtual Network Isolation: Managed Instances are deployed into your own Azure Virtual Network. This means they are not exposed to the public internet by default, allowing you to establish private connectivity from your on-premises data centers via VPN or ExpressRoute.
- Instance-Level Features: Because it acts like a full SQL Server instance, you get access to features like SQL Server Agent, Database Mail, Linked Servers, and native backup/restore functionality.
- Automated Management: Azure handles patching, backups, and high availability (HA) behind the scenes. You no longer need to worry about the Windows Server version or the underlying SQL Server patches, as these are managed automatically by the service.
Callout: Managed Instance vs. Azure SQL Database When choosing between Azure SQL Database and Managed Instance, the decision usually boils down to compatibility. If you are building a new, cloud-native application, Azure SQL Database is often preferred for its simplicity and lower entry cost. However, if you are migrating an existing application that relies on SQL Server Agent jobs, cross-database transactions, or specific server-level configurations, Managed Instance is the correct choice to ensure the application continues to function without architectural changes.
Pre-deployment Requirements: Networking and Configuration
Before you can deploy your first Managed Instance, you must prepare your Azure networking environment. Because Managed Instance is a "network-aware" service, it requires a dedicated subnet within a Virtual Network.
Subnet Requirements
Your subnet must be dedicated entirely to the Managed Instance. You cannot have other resources, such as virtual machines or application services, residing in the same subnet. Furthermore, the subnet must be configured with a specific delegation.
- Delegation: You must delegate the subnet to
Microsoft.Sql/managedInstances. - Network Security Group (NSG) Rules: You must configure specific inbound and outbound rules to allow the Azure management service to communicate with the instance and to allow application traffic to reach the SQL port (1433).
- Route Tables: You must ensure that the route table attached to the subnet does not interfere with the internal traffic required by the management service.
Warning: Subnet Sizing Once you deploy a Managed Instance into a subnet, you cannot easily move it or change the subnet configuration without redeploying the instance. Always plan for future growth by ensuring your subnet is large enough to accommodate multiple instances if necessary. A
/27CIDR block is the absolute minimum, but a/24is highly recommended for flexibility.
Step-by-Step Deployment Guide
Deploying an Azure SQL Managed Instance can be performed via the Azure Portal, Azure PowerShell, or the Azure CLI. For production environments, Infrastructure as Code (IaC) tools like Bicep or Terraform are highly recommended to ensure consistency.
Deployment via Azure Portal
- Navigate to the Azure Portal and search for "Azure SQL".
- Select "Create" and choose "Managed Instance".
- Fill in the project details, including subscription, resource group, and instance name.
- Navigate to the "Networking" tab and select the pre-configured VNet and dedicated subnet.
- Configure the "Compute + Storage" settings. You can choose between the "General Purpose" or "Business Critical" service tiers.
- Review and create. Note that the deployment process can take anywhere from 30 minutes to a few hours, as Azure must provision the underlying compute and storage resources within your VNet.
Deployment via Azure CLI
Using the CLI allows for faster, repeatable deployments. Below is a conceptual snippet for creating an instance:
# Define your variables
resourceGroup="my-resource-group"
instanceName="my-managed-instance"
subnetId="/subscriptions/.../subnets/my-managed-instance-subnet"
# Deploy the instance
az sql mi create \
--name $instanceName \
--resource-group $resourceGroup \
--location eastus \
--subnet $subnetId \
--license-type BasePrice \
--tier GeneralPurpose \
--storage 512 \
--vCores 4
Explanation: This command initiates the creation of a General Purpose instance with 4 vCores and 512 GB of storage. The --license-type BasePrice flag is used if you have existing SQL Server licenses with Software Assurance, which can significantly reduce your monthly costs.
Choosing the Right Service Tier
Azure SQL Managed Instance offers two primary service tiers, each catering to different workload requirements. Understanding these tiers is essential for cost management and performance optimization.
General Purpose
This tier is designed for most business workloads. It uses remote storage (Azure Premium SSD) and is optimized for applications with typical performance requirements.
- Use Case: Development, testing, and production workloads with standard I/O needs.
- Failover: Uses a single-node architecture, meaning failover involves moving the database to a new node, which results in a brief disconnection.
Business Critical
This tier is designed for high-performance applications with low latency requirements. It utilizes local SSD storage for the database and log files, providing much faster I/O.
- Use Case: High-transaction systems, real-time analytics, and applications that cannot tolerate failover-related disconnections.
- Failover: Features an "Always On" availability group architecture, meaning there are secondary replicas available for immediate failover with no manual intervention and minimal downtime.
| Feature | General Purpose | Business Critical |
|---|---|---|
| Storage Type | Remote Azure Premium SSD | Local NVMe SSD |
| Availability | Single node with failover | Always On HA (Multiple nodes) |
| Read-Scale | No (Primary only) | Yes (Read-only replicas available) |
| Latency | Standard | Very low |
Managing Security and Compliance
Security in Azure SQL Managed Instance is layered, starting from the network level and extending to the database contents. Because these instances often contain sensitive enterprise data, following the principle of least privilege is mandatory.
Authentication
Managed Instance supports two primary authentication methods:
- SQL Authentication: Traditional username and password. While simple, it is less secure and harder to manage at scale.
- Microsoft Entra ID (formerly Azure AD) Authentication: This is the industry standard. It allows you to use your organization's identity provider to authenticate users, enabling Multi-Factor Authentication (MFA) and conditional access policies.
Encryption
Data is encrypted at rest by default using Service-Managed Keys. For higher security requirements, you can implement Customer-Managed Keys (CMK) using Azure Key Vault. This gives you full control over the rotation and lifecycle of the encryption keys. Additionally, always enable Always Encrypted for sensitive columns to ensure that data remains encrypted even from database administrators.
Callout: The Importance of Entra ID Moving away from SQL logins toward Entra ID is the single most effective way to improve your security posture. By using Entra ID, you can disable SQL authentication entirely, reducing the attack surface and simplifying account offboarding when employees leave the organization.
Performance Tuning and Monitoring
Even though the platform manages the underlying infrastructure, performance tuning remains a responsibility of the database administrator. Monitoring is handled primarily through Azure Monitor and SQL Insights.
Key Monitoring Metrics
- CPU Utilization: If your CPU consistently stays above 80%, you should consider scaling up your vCores.
- I/O Latency: High latency is often a sign of storage bottlenecks. In General Purpose, this might mean you need to increase the storage size to gain higher IOPS.
- Log Write Wait Time: If this is high, your application may be generating too many transaction log writes, which can be mitigated by optimizing transaction sizes or moving to the Business Critical tier.
Query Store
Every Managed Instance comes with Query Store enabled by default. This is an invaluable tool for identifying performance regressions. You can view which queries are consuming the most resources and even force execution plans if a specific query performance degrades after an index change.
-- Example: Identifying top resource-consuming queries
SELECT TOP 10
q.query_id,
t.query_sql_text,
rs.avg_cpu_time,
rs.avg_logical_io_reads
FROM sys.query_store_query q
JOIN sys.query_store_query_text t ON q.query_text_id = t.query_text_id
JOIN sys.query_store_plan p ON q.query_id = p.query_id
JOIN sys.query_store_runtime_stats rs ON p.plan_id = rs.plan_id
ORDER BY rs.avg_cpu_time DESC;
Common Pitfalls and How to Avoid Them
Even experienced professionals encounter issues when working with Managed Instances. Many of these are related to networking and resource limitations.
1. Misconfigured NSG Rules
A common mistake is forgetting to allow the required management traffic. If your NSG rules are too restrictive, the Azure management plane will lose visibility into your instance, which can lead to failed updates or an inability to scale. Always refer to the official documentation for the exact list of inbound and outbound ports required for Managed Instance.
2. Ignoring Subnet Size
As mentioned earlier, once a subnet is associated with a Managed Instance, it is essentially "locked." If you start with a subnet that is too small, you cannot simply add more addresses to it later. You would have to move the instance to a new subnet, which requires a significant amount of coordination and downtime.
3. Over-provisioning Resources
It is tempting to provision the maximum number of vCores to "play it safe." However, Managed Instance is billed per vCore. By monitoring your actual usage, you can scale down during off-peak hours or right-size your instance, potentially saving thousands of dollars per year.
4. Forgetting SQL Agent Jobs
When migrating from an on-premises SQL Server, administrators often forget to script out their SQL Agent jobs. These jobs do not migrate automatically. You must manually export your jobs and recreate them on the Managed Instance.
Note: Using the Data Migration Assistant (DMA) Before moving any workload to a Managed Instance, always run the Data Migration Assistant. It will scan your existing SQL Server databases and generate a report detailing any features that are not supported or that require code changes. This is the most effective way to avoid surprises during the migration process.
Operational Best Practices
To maintain a healthy environment, follow these operational habits:
- Implement Automated Backups: While Azure provides automated backups (PITR) by default, ensure you understand your retention policies. You can configure long-term retention (LTR) for up to 10 years if your compliance requirements dictate it.
- Use Infrastructure as Code: Do not create instances manually in the portal for production. Use Terraform, Bicep, or ARM templates. This ensures that your network configurations, tags, and security settings are consistent across environments.
- Regularly Review Recommendations: Azure Advisor will provide recommendations regarding your Managed Instance, such as scaling suggestions or security improvements. Check this dashboard at least once a month.
- Maintain Database Maintenance Plans: Even in the cloud, you still need to manage index fragmentation and statistics. Use the
MaintenanceSolution.sqlscript (widely known in the SQL community) to automate these tasks on your Managed Instance.
Managing Connectivity: Private Endpoints vs. Public Endpoints
While Managed Instance is designed for internal VNet communication, you may occasionally need to provide external access.
- Private Endpoints: This is the default and most secure method. Applications inside your VNet (or connected via ExpressRoute/VPN) communicate directly with the instance's private IP address.
- Public Endpoints: You can enable a public endpoint for a Managed Instance, which exposes it to the internet. Warning: This is generally discouraged unless strictly necessary. If you must use a public endpoint, ensure you have a strong firewall policy and use IP-based access restrictions.
Advanced Feature Integration: Linked Servers and CLR
One of the primary reasons to choose Managed Instance over other cloud database options is its support for "legacy" features that are often required for enterprise applications.
Linked Servers
Managed Instance supports linked servers, allowing you to query data across different instances or even different data sources. This is critical for applications that perform cross-database reporting. When configuring a linked server, prefer using managed identities for authentication rather than hard-coding SQL credentials.
CLR Integration
Common Language Runtime (CLR) allows you to run .NET code inside the database. Managed Instance supports this, but with some restrictions on high-privilege operations. Always ensure that your CLR assemblies are signed and that you have a process for auditing the code running within your database.
The Migration Path: Moving Data to Managed Instance
Migrating to Azure SQL Managed Instance typically involves three main phases:
- Assessment: Use the Data Migration Assistant to identify compatibility issues.
- Preparation: Provision the target Managed Instance with the correct networking and security configurations.
- Execution: Use tools like the Azure Database Migration Service (DMS) or native backup and restore to move your data.
For large databases, the native backup and restore method is often the fastest. You can back up your on-premises database to Azure Blob Storage and then restore it directly to the Managed Instance using the RESTORE command.
-- Example: Restoring a backup from an Azure Blob Storage URL
RESTORE DATABASE [MyDatabase]
FROM URL = 'https://mystorageaccount.blob.core.windows.net/backups/MyDatabase.bak'
WITH RECOVERY;
Explanation: This command is powerful because it allows you to move terabytes of data into the cloud with minimal downtime. The Managed Instance handles the heavy lifting of reading from the storage account and reconstructing the database files.
Key Takeaways
As you wrap up this module, keep these core concepts in mind to ensure success with your Azure SQL Managed Instance deployments:
- Compatibility is King: Choose Managed Instance when your application requires features like SQL Agent, cross-database queries, or deep integration with legacy SQL Server components.
- Network First: Always prioritize the network design. A dedicated, properly delegated subnet is the foundation of a healthy Managed Instance. You cannot "fix" a bad subnet architecture after deployment.
- Right-Size Your Tiers: Don't default to Business Critical unless your workload truly requires the performance and high availability. Start with General Purpose and use monitoring to determine if you need to upgrade.
- Security by Identity: Move away from legacy SQL logins. Use Microsoft Entra ID for all authentication to leverage modern security controls like MFA and conditional access.
- Automation is Mandatory: Use IaC (Bicep/Terraform) for deployment and automation scripts for maintenance (index/stats management). Manual management is prone to error and makes scaling difficult.
- Plan the Migration: Use the Data Migration Assistant. Never attempt a migration without first understanding the compatibility gaps between your current on-premises environment and the cloud target.
- Monitor and Optimize: Use Query Store and Azure Monitor to keep an eye on performance. A Managed Instance is not "set it and forget it"—it requires ongoing attention to ensure it continues to meet the needs of your application.
By following these practices, you will be well-equipped to deploy and maintain robust, high-performing SQL environments in Azure, bridging the gap between traditional database management and the benefits of modern cloud services.
Reach the last section to complete this lesson and earn points — you're on section 1 of 12.
- Introduction to Azure SQL Services
- Introduction to Azure SQL Services Quiz5q
- Azure SQL Database Deployment
- Azure SQL Database Deployment Quiz5q
- Azure SQL Managed Instance
- Azure SQL Managed Instance Quiz5q
- SQL Server on Azure VMs
- SQL Server on Azure VMs Quiz5q
- Elastic Pools Configuration
- Elastic Pools Configuration Quiz5q
- Serverless SQL Database
- Serverless SQL Database Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons