Azure SQL11 min read

Azure SQL Cost Optimization: Proven Strategies to Reduce Your Cloud Database Spend by 40%

Practical techniques to optimize Azure SQL costs without sacrificing performance. Learn from real-world cases and discover automated solutions for continuous cost management.

By SQLOPTIMISE Team

Azure SQL Cost Optimization: Reducing Cloud Database Spend

Azure SQL Database and Managed Instance offer tremendous scalability and features, but costs can escalate quickly if not managed properly. As Buck Woody (Microsoft's cloud data evangelist) emphasizes, "The cloud gives you the ability to scale infinitely - and bill infinitely too." This guide provides proven strategies to optimize Azure SQL costs while maintaining or improving performance.

Understanding Azure SQL Pricing Models

Azure SQL Database Pricing Tiers

DTU-Based (Database Transaction Units):

  • Basic: Low-performance, small databases
  • Standard (S0-S12): General purpose workloads
  • Premium (P1-P15): High-performance, mission-critical

vCore-Based:

  • General Purpose: Balanced compute/memory
  • Business Critical: Low latency, high IOPS
  • Hyperscale: Massive scale databases (100TB+)

Key Insight from Anna Hoffman (Microsoft): "vCore gives you more control and often better value for larger workloads."

Cost Components

  1. Compute (DTUs or vCores)
  2. Storage (database size + backups)
  3. Backup Retention (beyond 7 days)
  4. Networking (data egress)
  5. High Availability/DR (geo-replication, failover groups)

Cost Optimization Strategy #1: Right-Sizing

Identifying Over-Provisioned Databases

Brent Ozar's approach using Azure Metrics:

-- Check actual DTU usage in Azure SQL Database
SELECT TOP 100
    end_time,
    avg_cpu_percent,
    avg_data_io_percent,
    avg_log_write_percent,
    max_worker_percent,
    max_session_percent
FROM sys.dm_db_resource_stats
ORDER BY end_time DESC

Analysis Guidelines:

  • Consistently <40% CPU: Consider downsizing
  • Consistently >80% CPU: Consider upsizing or optimization
  • Storage >80% full: Plan for growth or archive old data

Azure Advisor Recommendations

Kendra Little recommends: "Azure Advisor is your first stop for optimization suggestions."

Access via Azure Portal → Advisor → Cost Recommendations

Common Recommendations:

  • Downsize underutilized databases
  • Switch from DTU to vCore for better value
  • Implement elastic pools for similar workload databases
  • Use serverless compute for intermittent workloads

Using Serverless Compute

Anna Hoffman's guidance on serverless:

-- Create serverless database (Azure Portal or PowerShell)
-- Auto-pauses when inactive
-- Auto-scales within specified range

New-AzSqlDatabase `
    -ResourceGroupName "YourResourceGroup" `
    -ServerName "yourserver" `
    -DatabaseName "YourDatabase" `
    -Edition "GeneralPurpose" `
    -ComputeModel Serverless `
    -ComputeGeneration Gen5 `
    -VCore 2 `
    -MinimumCapacity 0.5 `
    -AutoPauseDelayInMinutes 60

Best For:

  • Development/test databases
  • Intermittent workloads
  • Databases with predictable idle periods

Savings: Up to 70% for databases idle 12+ hours daily

Cost Optimization Strategy #2: Storage Management

Implement Data Compression

Paul Randal demonstrates significant storage savings:

-- Check current compression status
SELECT 
    OBJECT_SCHEMA_NAME(p.object_id) AS SchemaName,
    OBJECT_NAME(p.object_id) AS TableName,
    i.name AS IndexName,
    p.data_compression_desc,
    p.rows,
    (SUM(a.total_pages) * 8) / 1024.0 AS TotalSpaceMB
FROM sys.partitions p
INNER JOIN sys.indexes i ON p.object_id = i.object_id 
    AND p.index_id = i.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
WHERE p.data_compression_desc = 'NONE'
    AND p.rows > 0
GROUP BY p.object_id, i.name, p.data_compression_desc, p.rows
HAVING SUM(a.total_pages) * 8 / 1024.0 > 100  -- Tables > 100MB
ORDER BY TotalSpaceMB DESC

Implement PAGE compression (best compression ratio):

-- Enable PAGE compression
ALTER INDEX ALL ON Sales.Orders
REBUILD WITH (DATA_COMPRESSION = PAGE, ONLINE = ON)

Expected Savings: 40-60% storage reduction for typical OLTP tables

Archive Old Data

Erik Darling's practical approach:

-- Move old data to cheaper storage tier
-- 1. Create archive table with columnstore
CREATE TABLE Sales.OrdersArchive (
    OrderID INT NOT NULL,
    OrderDate DATETIME2,
    CustomerID INT,
    -- ... other columns
    INDEX CCI_OrdersArchive CLUSTERED COLUMNSTORE
)

-- 2. Move data older than 2 years
BEGIN TRANSACTION
    INSERT INTO Sales.OrdersArchive
    SELECT * FROM Sales.Orders
    WHERE OrderDate < DATEADD(YEAR, -2, GETDATE())
    
    DELETE FROM Sales.Orders
    WHERE OrderDate < DATEADD(YEAR, -2, GETDATE())
COMMIT

-- 3. Create view for transparent access
CREATE VIEW Sales.OrdersComplete AS
    SELECT * FROM Sales.Orders
    UNION ALL
    SELECT * FROM Sales.OrdersArchive

Cost Impact:

  • Reduce active database size
  • Lower backup storage costs
  • Faster query performance on active data
  • Columnstore provides 10x compression for archives

Optimize Backup Retention

Default: 7 days free backup retention
Extended: 8-35 days = additional costs

-- Check current retention policy
SELECT backup_retention_period_in_days
FROM sys.database_recovery_settings

-- Adjust if excessive
-- Azure Portal  SQL Database  Backup retention

Glenn Berry's recommendation: "Balance compliance requirements with costs. Not all databases need 35-day retention."

Cost Optimization Strategy #3: Elastic Pools

When to Use Elastic Pools

Bob Ward (Microsoft Principal Architect) explains: "If you have multiple databases with similar workloads and complementary usage patterns, elastic pools can save 30-50%."

Ideal Candidates:

  • Multi-tenant SaaS applications
  • Multiple similar-sized databases
  • Complementary usage patterns (different peak times)
  • Databases in same region
# Create elastic pool
New-AzSqlElasticPool `
    -ResourceGroupName "YourResourceGroup" `
    -ServerName "yourserver" `
    -ElasticPoolName "YourPool" `
    -Edition "Standard" `
    -Dtu 400 `
    -DatabaseDtuMax 50 `
    -DatabaseDtuMin 10

Monitoring Pool Usage

-- Check elastic pool resource usage
SELECT
    end_time,
    avg_cpu_percent,
    avg_data_io_percent,
    avg_log_write_percent,
    max_session_percent,
    max_worker_percent,
    storage_in_megabytes
FROM sys.elastic_pool_resource_stats
ORDER BY end_time DESC

Optimization Rule: If pool consistently <60% utilized across all metrics, you're over-provisioned.

Cost Optimization Strategy #4: Query Performance Tuning

Poor Queries = Higher Costs

Kendra Little's insight: "A single bad query can force you into a higher pricing tier."

Find expensive queries in Azure SQL:

-- Top resource-consuming queries
SELECT TOP 20
    qs.execution_count,
    qs.total_worker_time / 1000 AS total_cpu_ms,
    qs.total_worker_time / qs.execution_count / 1000 AS avg_cpu_ms,
    qs.total_elapsed_time / 1000 AS total_elapsed_ms,
    qs.total_logical_reads,
    qs.total_logical_writes,
    SUBSTRING(qt.text, (qs.statement_start_offset/2)+1,
        ((CASE qs.statement_end_offset
            WHEN -1 THEN DATALENGTH(qt.text)
            ELSE qs.statement_end_offset
        END - qs.statement_start_offset)/2) + 1) AS query_text
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
ORDER BY qs.total_worker_time DESC

Using Azure SQL Database Query Performance Insights

Joey D'Antoni (Microsoft Data Platform MVP) recommends: "Query Performance Insights is free and invaluable."

Access: Azure Portal → SQL Database → Intelligent Performance → Query Performance Insight

Key Features:

  • Top resource-consuming queries
  • Long-running queries
  • Query regression detection
  • Historical query performance

Automatic Tuning

Enable automatic tuning for free performance improvements:

-- Enable automatic tuning
ALTER DATABASE CURRENT
SET AUTOMATIC_TUNING (
    FORCE_LAST_GOOD_PLAN = ON,
    CREATE_INDEX = ON,
    DROP_INDEX = ON
)

Anna Hoffman notes: "Automatic tuning can improve performance by 20-30% without manual intervention."

Cost Optimization Strategy #5: Reserved Capacity

Azure SQL Reserved Capacity Pricing

Savings: Up to 33% with 1-year commitment, 54% with 3-year

Buck Woody's advice: "If you know your baseline capacity needs, reserved pricing is a no-brainer."

Considerations:

  • Commit to specific region
  • Can exchange for different size/tier
  • Best for stable, predictable workloads
# Purchase reserved capacity (via Azure Portal or PowerShell)
# Portal: Azure Portal  Reservations  Add  SQL Database

Cost Optimization Strategy #6: Smart Data Architecture

Implement Read Scale-Out

Business Critical tier includes free read-only replicas:

-- Direct read-only queries to replica
-- Connection string: ApplicationIntent=ReadOnly
SELECT * FROM Orders
WHERE CustomerID = @CustomerID

Benefit: Offload reporting queries without additional cost

Leverage Azure Synapse Link

Aaron Bertrand suggests: "For heavy analytics, Azure Synapse Link avoids DTU consumption on OLTP database."

Use Case: Complex analytical queries, data warehousing scenarios

Consider Azure SQL Edge for IoT

For IoT scenarios with local processing needs, Azure SQL Edge offers lower costs than centralized Azure SQL.

Automated Cost Optimization with aDBA

Manual cost optimization requires continuous monitoring and analysis. aDBA automates this process:

Continuous Cost Monitoring

aDBA tracks:

  • Resource utilization trends across all databases
  • Query performance degradation that increases costs
  • Unused resources and over-provisioned capacity
  • Optimal sizing recommendations based on actual usage

Intelligent Right-Sizing

Automated analysis:

  • Compares actual vs. provisioned resources
  • Recommends specific tier changes with cost impact
  • Simulates workload on different tiers
  • Schedules scaling operations for minimal impact

Query Cost Analysis

aDBA identifies:

  • Queries driving up DTU/vCore consumption
  • Missing indexes increasing costs
  • Inefficient queries suitable for optimization
  • Opportunities for query rewrite

Automated Archival

Scheduled data archival:

  • Policy-based data retention
  • Automatic compression application
  • Transparent access via views
  • Storage cost tracking and reporting

Learn more about aDBA's cost optimization features →

Real-World Case Study

Scenario: SaaS Platform with 200 Databases

Initial State:

  • 200 Standard S3 databases (@$152/mo each)
  • Total monthly cost: $30,400
  • Average utilization: 35%

Optimizations Applied:

  1. Consolidated into 4 elastic pools: $15,200/mo
  2. Implemented serverless for dev/test (50 dbs): $2,100/mo
  3. Applied PAGE compression: Reduced storage by 45%
  4. Archived 2+ year old data: Further storage reduction
  5. Query optimization: Prevented need for higher tiers

Results:

  • New monthly cost: $18,000
  • Savings: 40% ($12,400/month, $148,800/year)
  • Improved query performance
  • Better scalability

Monitoring and Continuous Optimization

Azure Cost Management

Kendra Little emphasizes: "Set up cost alerts before costs surprise you."

# Set up budget alert
New-AzConsumptionBudget `
    -Amount 5000 `
    -Name "SQL Database Budget" `
    -Category Cost `
    -TimeGrain Monthly `
    -StartDate (Get-Date) `
    -Notification @{
        Enabled = $true
        Operator = "GreaterThan"
        Threshold = 90
        ContactEmails = @("dba@yourcompany.com")
    }

Key Metrics to Track

  1. DTU/vCore utilization %
  2. Storage usage trend
  3. Query performance metrics
  4. Backup storage costs
  5. Data transfer costs

Best Practices Summary

  1. Right-size continuously: Usage patterns change
  2. Leverage serverless: For non-production and intermittent workloads
  3. Implement compression: Free storage savings
  4. Use elastic pools: For similar workload patterns
  5. Optimize queries: Performance AND cost benefits
  6. Consider reserved capacity: For stable workloads
  7. Archive old data: Move to cheaper storage
  8. Monitor costs: Set alerts and review monthly
  9. Automate optimization: Use tools like aDBA for continuous monitoring

When to Get Expert Help

Azure SQL cost optimization can be complex, especially at scale. Consider expert assistance when:

  • Managing dozens or hundreds of databases
  • Costs are growing but utilization is unclear
  • Need to implement elastic pools across multiple servers
  • Struggling with query performance impacting costs
  • Want automated monitoring and optimization

SQLOPTIMISE offers comprehensive Azure SQL cost optimization:

  • Complete cost analysis and baseline
  • Right-sizing recommendations with ROI calculation
  • Query performance optimization
  • Elastic pool design and implementation
  • Automated monitoring setup with aDBA
  • Ongoing cost management services

Schedule a free Azure SQL cost assessment →

Conclusion

Azure SQL provides tremendous flexibility and performance, but costs require active management. By implementing the strategies outlined here - right-sizing, storage optimization, elastic pools, query tuning, and automated monitoring - you can achieve significant cost savings (40%+ in many cases) while maintaining or improving performance.

For continuous optimization, automated solutions like aDBA provide the monitoring and intelligence needed to keep costs under control as your workload evolves.

Further Reading

  • Anna Hoffman: "Azure SQL Database Purchasing Models"
  • Buck Woody: "Cost Optimization in Azure"
  • Joey D'Antoni: "Performance Tuning Azure SQL Database"
  • Bob Ward: "Azure SQL Managed Instance Deep Dive"
  • Kendra Little: "When to Use Azure SQL Elastic Pools"

Need help optimizing your Azure SQL costs? Contact SQLOPTIMISE for a comprehensive cost analysis and optimization plan tailored to your environment.

Need Expert SQL Help?

Our SQL optimization experts are ready to help you implement these strategies and optimize your database performance.

Schedule Free Consultation