SQL Server on Azure VMs

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 11 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Lesson: SQL Server on Azure Virtual Machines

Introduction: Understanding Infrastructure as a Service (IaaS) for SQL Server

When organizations begin their journey to the cloud, one of the most common initial hurdles is deciding how to migrate existing relational databases. While managed services like Azure SQL Database offer a "platform as a service" (PaaS) experience that removes the burden of patching and hardware maintenance, many legacy applications require a level of control that only a full operating system can provide. This is where SQL Server on Azure Virtual Machines (VMs) comes into play.

SQL Server on Azure VMs is an Infrastructure as a Service (IaaS) offering. It provides you with a virtual machine running Windows Server or Linux, onto which a licensed version of SQL Server is installed. Unlike managed services, you have full administrative access to the underlying operating system and the SQL Server instance itself. This makes it an ideal landing zone for applications that require specific third-party drivers, custom CLR assemblies, or older versions of SQL Server that are not supported in managed environments.

Understanding this service is critical because it represents the bridge between traditional on-premises data management and the modern cloud ecosystem. By choosing this path, you retain the familiarity of your current administrative workflows—such as using SQL Server Management Studio (SSMS), SQL Server Agent, and standard backup utilities—while gaining the agility of Azure’s global infrastructure. This lesson will guide you through the architectural considerations, deployment strategies, and operational best practices required to manage SQL Server on Azure VMs effectively.


Not read yet

The Architectural Foundation: IaaS vs. PaaS

To make an informed decision about your database strategy, you must understand the distinction between running SQL Server in a virtual machine and using a managed service. In an IaaS model, you are responsible for the "stack" from the operating system upward. This includes Windows or Linux updates, SQL Server patching, high availability configuration, and backup scheduling.

Callout: The Control Spectrum When choosing between SQL Server on Azure VMs and Azure SQL Database, consider the "Control vs. Effort" trade-off. Azure VMs provide maximum control over the environment, allowing for non-standard configurations and deep OS-level tuning. However, this control demands more human effort to maintain security, performance, and availability compared to managed services where the cloud provider assumes these responsibilities.

When to choose SQL Server on Azure VMs:

  • Legacy Compatibility: Your application relies on features like SQL Server Reporting Services (SSRS) or Integration Services (SSIS) that are not natively supported in Azure SQL Database.
  • Operating System Access: You need to install custom agents, third-party monitoring tools, or specific file system drivers that require administrative rights on the host.
  • Migration Ease: You are performing a "lift and shift" migration where you want to move your existing on-premises virtual machine to the cloud with minimal changes to the database engine configuration.
  • Specific Version Requirements: You need an older version of SQL Server (such as 2012 or 2014) that is no longer supported in modern PaaS offerings.

Not read yet

Deploying SQL Server on Azure VMs

Deploying SQL Server on Azure VMs is a straightforward process, but it requires careful planning regarding storage, compute sizing, and networking. Azure provides pre-configured images in the Azure Marketplace that include both the Windows/Linux operating system and the SQL Server engine, which simplifies the licensing and setup process significantly.

Step-by-Step Deployment Guide

  1. Select the Image: Navigate to the Azure Portal, select "Create a resource," and search for "SQL Server." You will see options like "SQL Server 2022 on Windows Server 2022." Choosing a pre-configured image is recommended because these images include the "SQL IaaS Agent Extension," which automatically handles tasks like automated backups and patching.
  2. Size the VM: Choose an appropriate series. The E-series or M-series VMs are generally preferred for database workloads because they offer higher memory-to-core ratios and are optimized for memory-intensive applications.
  3. Storage Configuration: This is the most critical step. Never use the temporary "D:" drive for database files, as it is ephemeral and will be wiped on reboot. Use Azure Managed Disks (Premium SSD or Ultra Disk) to ensure consistent I/O performance.
  4. Networking: Configure a Virtual Network (VNet) and a Network Security Group (NSG). Ensure that port 1433 (or your custom SQL port) is only accessible from your application tier or authorized jump boxes to minimize the attack surface.
  5. SQL Server Settings: During deployment, you can configure the SQL connectivity (Public, Private, or None), authentication mode (Windows or Mixed), and storage optimization.

Tip: SQL IaaS Agent Extension Always ensure the SQL IaaS Agent Extension is installed and running. It enables features like Automated Backup, Automated Patching, and Key Vault integration. You can check its status using the Azure CLI: az sql vm show -n <vm-name> -g <resource-group>.


Not read yet

Optimizing Performance: Beyond Default Settings

One of the most common pitfalls with SQL Server on Azure VMs is treating the VM like a physical server without accounting for cloud-specific storage limitations. In a local data center, you might be used to adding physical disks to a RAID array. In Azure, performance is often governed by IOPS (Input/Output Operations Per Second) and throughput limits associated with the disk size.

Storage Best Practices

  • Separate Data and Logs: Place your data files (MDF/NDF) and transaction log files (LDF) on separate disks. This allows Azure to distribute the I/O load across different storage controllers and prevents contention.
  • TempDB Placement: Always move TempDB to a separate, high-performance disk (or even the local SSD "D:" drive if configured correctly for volatile data). Because TempDB is used heavily for sorting, joins, and temporary objects, it is often the bottleneck in high-transaction environments.
  • Disk Caching: Use "Read-only" caching for data files and "None" for log files. This is a standard configuration that aligns with the way SQL Server interacts with the file system.

Compute Optimization

  • Memory Reservation: Ensure that the SQL Server "Max Server Memory" setting is configured correctly. By default, SQL Server will try to consume as much memory as it can. Leave enough overhead for the operating system to prevent swapping, which can severely degrade database performance.
  • Core Affinity: If you are running a very high-concurrency workload, verify that the SQL Server process is utilizing all available CPU cores. Sometimes, virtual machines with high core counts require specific configuration to ensure the SQL engine is distributing threads effectively.

Not read yet

Security and Compliance

When you manage your own VM, you are responsible for the security of the host. This includes everything from OS-level firewall rules to the encryption of data at rest.

Key Security Measures:

  1. Azure Disk Encryption: Utilize Azure Disk Encryption (ADE) to encrypt the virtual hard disks. This ensures that even if someone gains physical access to the storage, the data remains unreadable.
  2. SQL Server Transparent Data Encryption (TDE): In addition to disk encryption, use TDE within SQL Server. TDE provides encryption at the file level, protecting your data even if a database file is moved or copied.
  3. Network Isolation: Never expose port 1433 to the public internet. Use a VPN or ExpressRoute for connectivity. If you must connect remotely, use a Bastion host or a Just-In-Time (JIT) VM access policy to open the management port only when required.
  4. Patching: Use the "Automated Patching" feature provided by the SQL IaaS Agent to ensure that security updates for SQL Server and the Windows OS are applied during maintenance windows without manual intervention.

Warning: The Public IP Trap A common mistake is assigning a Public IP address directly to the VM and opening the SQL port to the internet. This exposes your instance to automated brute-force attacks. Always place your SQL Server in a private subnet and use an internal load balancer or a jump box for access.


Not read yet

High Availability and Disaster Recovery

High Availability (HA) and Disaster Recovery (DR) in an IaaS environment require manual configuration. Unlike PaaS, where HA is often a toggle switch, in an IaaS VM, you must build the infrastructure to support it.

High Availability Options:

  • Always On Availability Groups (AGs): This is the industry standard for SQL Server HA. You can set up a cluster of Azure VMs across different Availability Zones (AZs) or even different regions. This provides near-zero downtime in the event of a single VM or data center failure.
  • Failover Cluster Instances (FCI): This provides instance-level protection. If the SQL Server service fails, the instance fails over to another node in the cluster. This requires shared storage, which in Azure is typically handled via Azure Shared Disks or third-party solutions like SIOS DataKeeper.
  • Log Shipping: For a more cost-effective disaster recovery solution, Log Shipping remains a viable option. It involves periodically backing up the transaction logs from the primary server and restoring them to a secondary server. It is not as instantaneous as AGs but is much simpler to implement and maintain.
Feature Always On Availability Groups Log Shipping
Failover Speed Seconds (Automatic) Minutes/Hours (Manual)
Complexity High Low
Data Loss Zero (Synchronous) Minimal (Asynchronous)
Use Case Mission-critical apps Disaster recovery/Reporting

Not read yet

Practical Code Snippets for Management

Managing SQL Server on Azure VMs is often done via T-SQL or PowerShell. Below are some essential commands to help you manage your environment.

Checking SQL IaaS Extension Status

If you need to verify that your VM is properly registered with the SQL IaaS agent, use this PowerShell command:

# Get the status of the SQL IaaS extension for a specific VM
Get-AzSqlVM -ResourceGroupName "MyResourceGroup" -Name "MySQLVM"

Configuring Automated Backup

Automated backups are a core feature of the SQL IaaS agent. You can configure this via PowerShell to ensure your backups are stored in a secure Azure Blob Storage container:

# Configure automated backup for a SQL VM
Set-AzSqlVM -ResourceGroupName "MyResourceGroup" -Name "MySQLVM" `
    -AutoBackupSettingEnable `
    -AutoBackupSettingRetentionPeriod 30 `
    -AutoBackupSettingStorageAccountName "mystorageaccount"

Optimizing Memory

It is a best practice to set a cap on SQL Server memory. You can execute this via T-SQL inside SSMS:

-- Set Max Server Memory to 80% of total system memory (e.g., 16GB)
EXEC sys.sp_configure N'show advanced options', N'1';
RECONFIGURE;
EXEC sys.sp_configure N'max server memory (MB)', 16384;
RECONFIGURE;

Not read yet

Troubleshooting Common Pitfalls

Even with careful planning, issues arise. Being able to diagnose performance or connectivity problems is part of being an effective database administrator.

1. High CPU or Latency

If you notice high CPU usage, first check the "SQL Server Wait Statistics." High PAGEIOLATCH waits often indicate that your storage is not providing enough throughput. Use the Azure Portal "Metrics" tab for your VM to look at "Disk Read/Write Bytes per second." If you are hitting your IOPS limit, it is time to upgrade your disk tier or stripe multiple disks together.

2. Connectivity Issues

If your application cannot connect to the SQL Server, follow this checklist:

  • NSG Rules: Check the Network Security Group associated with the NIC or subnet. Is port 1433 open?
  • SQL Server Configuration: Ensure that "Remote Connections" are allowed in the SQL Server properties.
  • Windows Firewall: Even if the Azure NSG is open, the Windows Firewall inside the VM might be blocking the connection. Ensure an inbound rule exists for the SQL port.

3. Backup Failures

If automated backups fail, check the SQL Server error logs and the "SQLIaaSExtension" logs. Often, this is caused by a credential issue where the VM no longer has permission to write to the Azure Storage account. Re-running the registration command can often fix these permission drift issues.


Not read yet

Best Practices Checklist

To ensure your SQL Server on Azure VMs remains stable and performant, follow these industry-standard practices:

  • Use Premium Storage: Always use SSD-based storage for production workloads. Avoid HDD storage unless it is for development or non-critical archive databases.
  • Monitor with Azure Monitor: Enable VM Insights. It provides deep visibility into the performance of the operating system and the SQL engine, allowing you to catch issues before they impact users.
  • Keep Tools Updated: Keep your SQL Server version and Windows updates current. Use the Azure update management feature to schedule these patches during off-peak hours.
  • Use Tags: Tag your resources (e.g., Environment: Production, Owner: DataTeam) to simplify billing and resource management.
  • Right-Sizing: Monitor your CPU and memory usage regularly. If you find you are consistently using less than 20% of your resources, downsize the VM to save costs.

Callout: The Importance of "Right-Sizing" In the cloud, paying for idle capacity is a common waste of budget. Because Azure allows you to resize VMs with a simple restart, you should review your performance metrics every quarter. If your database workload is consistently light, moving to a smaller VM size can result in significant monthly savings without impacting performance.


Not read yet

Comparison: Azure SQL Database vs. SQL Server on Azure VM

Feature Azure SQL Database (PaaS) SQL Server on Azure VM (IaaS)
OS Access None Full Administrative
Patching Automated Managed by you
Migration Effort Higher (Code changes) Low (Lift and shift)
High Availability Built-in Configurable (Manual)
Version Control Always latest Specific version support

Key Takeaways for Success

Running SQL Server on Azure VMs is a powerful way to retain control over your database environment while moving to the cloud. By following the guidelines in this lesson, you can ensure a successful migration and ongoing stability.

  1. Understand the Responsibility Model: Remember that IaaS puts the burden of OS and SQL maintenance on your shoulders. Ensure your team is prepared for patching, backup management, and security hardening.
  2. Prioritize Storage Performance: In Azure, storage is almost always the bottleneck. Use Premium SSDs or Ultra Disks, separate data/logs/TempDB, and be mindful of your IOPS limits.
  3. Leverage the SQL IaaS Extension: This extension is your best friend. It automates critical tasks like backups and patching, reducing the administrative overhead significantly.
  4. Security is Non-Negotiable: Use private networking, disk encryption, and TDE. Never expose your SQL port to the internet.
  5. Plan for HA/DR: If your database is critical, do not rely on a single VM. Use Availability Groups or Failover Cluster Instances to ensure uptime.
  6. Monitor and Right-Size: Use Azure Monitor to keep an eye on performance and adjust your VM size to match your actual workload requirements.
  7. Keep Documentation: Maintain a record of your configuration, especially for complex HA setups. Documentation is vital when troubleshooting issues in a cloud environment where the infrastructure is abstracted.

By mastering these concepts, you transition from simply "hosting" a database in the cloud to architecting a resilient, high-performance data platform that serves your organization's needs for years to come. Whether you are migrating a legacy system or building a new application that requires specific OS-level access, SQL Server on Azure VMs provides the flexibility and power to get the job done.


Not read yet

Common Questions (FAQ)

Q: Can I move my existing SQL Server license to Azure?

A: Yes, through the Azure Hybrid Benefit, you can use your existing SQL Server licenses with Software Assurance to pay a reduced rate for your Azure VM. This is a significant cost-saving measure for many organizations.

Q: Is it possible to upgrade SQL Server on an Azure VM?

A: Yes, because you have full control over the OS, you can perform in-place upgrades just as you would on a physical server. However, always test the upgrade in a staging environment first to ensure application compatibility.

Q: How do I handle backups if I don't use the SQL IaaS extension?

A: If you choose not to use the extension, you must manually configure SQL Server Agent jobs to back up to an Azure Blob Storage container using a Shared Access Signature (SAS) token or a managed identity. This is more complex and prone to configuration errors compared to the automated approach.

Q: Does SQL Server on Azure VM support Linux?

A: Yes, Microsoft fully supports SQL Server on Linux distributions like Ubuntu, RHEL, and SUSE on Azure VMs. The management principles remain largely the same, though the underlying OS administration will differ.

Q: What happens if I exceed my disk IOPS limit?

A: If your workload exceeds the IOPS limit of your disk, the disk will "throttle." This means that read and write operations will queue up, leading to high latency and potentially causing application timeouts. Always monitor your "Percentage Disk Read/Write IOPS Consumed" in the Azure Portal.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.