Home
%3CLINGO-SUB%20id%3D%22lingo-sub-386234%22%20slang%3D%22en-US%22%3EReaching%20Azure%20disk%20storage%20limit%20on%20General%20Purpose%20Azure%20SQL%20Database%20Managed%20Instance%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-386234%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Aug%2020%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3EAzure%20SQL%20Database%20Managed%20Instance%20General%20Purpose%20(GP)%20is%20SQL%20Server%20implementation%20on%20Azure%20cloud%20that%20keeps%20all%20database%20files%20on%20Azure%20storage.%20In%20this%20post%20you%20will%20learn%20how%20Managed%20Instance%20General%20Purpose%20allocates%20disks%20in%20the%20storage%20layer%20at%20the%20back%20end%20and%20why%20this%20is%20important.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3EPlease%20note%20this%20article%20does%20not%20apply%20to%20Business%20Critical%20edition%20of%20Managed%20Instance.%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3EAzure%20SQL%20Database%20Managed%20Instance%20General%20Purpose%20tier%20separates%20compute%20and%20storage%20layers%20where%20the%20database%20files%20are%20placed%20on%20Azure%20Premium%20disks.%20Managed%20Instance%20uses%20pre-defined%20sizes%20of%20azure%20disks%20(128GB%2C%20256GB%2C%20512GB%2C%20etc.)%20for%20every%20file%2C%20so%20every%20file%20is%20placed%20on%20a%20single%20disk%20with%20the%20smallest%20size%20that%20is%20large%20enough%20to%20fit%20the%20file%20with%20the%20current%20file%20size.%20%3CBR%20%2F%3E%3CBR%20%2F%3EOnce%20you%20provision%20Managed%20Instance%20you%20have%20the%20following%20two%20storage%20limits%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3EManaged%20Instance%20General%20Purpose%20user%20storage%3C%2FSTRONG%3E%20cannot%20exceed%208TB.%20Your%20max%20storage%20size%20cannot%20be%20greater%20than%208TB%2C%20and%20you%20are%20paying%20only%20for%20the%20amount%20of%20storage%20size%20that%20you%20choose%20in%20portal.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EMaximum%20of%20280%20data%20files%3C%2FSTRONG%3E%20on%20the%20General%20Purpose%20instance.%20This%20limitation%20is%20due%20to%20how%20Azure%20premium%20disk%20storage%20is%20allocated%20internally.%20280%20files%20placed%20on%20the%20smallest%20128GB%20disk%20will%20reach%20beyond%20the%2035TB%20of%20maximum%20internal%20Azure%20premium%20storage%20limit.%20Please%20note%20that%20this%20limit%20is%20internal%20to%20Azure%20storage%20under%20the%20hood%2C%20and%20that%20customers%20can%20still%20only%20use%20up%20to%208TB%20of%20storage%20for%20the%20Managed%20Instance.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3EWhen%20you%20create%20database%20files%2C%20they%20are%20allocated%20on%20Azure%20premium%20disks%20with%20sizes%20that%20are%20greater%20than%20the%20actual%20file%20size%2C%20so%20practically%20this%20is%20%22internal%20fragmentation%22%20of%20files.%20This%20is%20implemented%20because%20Azure%20premium%20disk%20storage%20offers%20fixed%20set%20of%20disk%20sizes%2C%20so%20Managed%20Instance%20tries%20to%20fit%20database%20files%20on%20a%20matching%20disk.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3EThe%20number%20of%20data%20files%20per%20General%20Purpose%20Managed%20Instance%20cannot%20be%20greater%20than%20280%20files%20summing%20up%20to%20the%20maximum%20of%2035TB%20of%20storage%20on%20Azure%20premium%20disks%20with%20internal%20fragmentation.%20If%20you%20reach%20this%20limit%20you%20might%20start%20getting%20errors%20even%20if%20you%20have%20not%20actually%20reached%20the%20user-defined%20Managed%20Instance%20storage%20limit%20of%208TB.%20%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20this%20post%2C%20you%20will%20see%20some%20scripts%20that%20can%20help%20you%20to%20see%20are%20you%20reaching%20this%20storage%20limit.%20%3CBR%20%2F%3E%3CBR%20%2F%3EFirst%2C%20we%20will%20create%20a%20schema%20and%20view%20that%20wraps%20standard%20sys.master_files%20view%20and%20returns%20the%20allocated%20disk%20size%20for%20every%20file%3A%3C%2FP%3E%0A%3CPRE%3ECREATE%20SCHEMA%20mi%3B%20%0AGO%20%0ACREATE%20OR%20ALTER%20VIEW%20mi.master_files%20%0AAS%20%0AWITH%20mi_master_files%20AS%20%0A(%20SELECT%20*%2C%20size_gb%20%3D%20CAST(size%20*%208.%20%2F%201024%20%2F%201024%20AS%20decimal(12%2C4))%20%0AFROM%20sys.master_files%20)%20%0ASELECT%20*%2C%20azure_disk_size_gb%20%3D%20IIF(%20%0Adatabase_id%20%26lt%3B%26gt%3B%202%2C%20%0ACASE%20WHEN%20size_gb%20%26lt%3B%3D%20128%20THEN%20128%20%0AWHEN%20size_gb%20%26gt%3B%20128%20AND%20size_gb%20%26lt%3B%3D%20256%20THEN%20256%20%0AWHEN%20size_gb%20%26gt%3B%20256%20AND%20size_gb%20%26lt%3B%3D%20512%20THEN%20512%20%0AWHEN%20size_gb%20%26gt%3B%20512%20AND%20size_gb%20%26lt%3B%3D%201024%20THEN%201024%20%0AWHEN%20size_gb%20%26gt%3B%201024%20AND%20size_gb%20%26lt%3B%3D%202048%20THEN%202048%20%0AWHEN%20size_gb%20%26gt%3B%202048%20AND%20size_gb%20%26lt%3B%3D%204096%20THEN%204096%20%0AELSE%208192%20%0AEND%2C%20NULL)%20%0AFROM%20mi_master_files%3B%20%3C%2FPRE%3E%0A%3CP%3ENow%20we%20can%20see%20the%20size%20allocated%20for%20the%20underlying%20Azure%20Premium%20Disks%20for%20every%20database%20file%3A%20%3CBR%20%2F%3ESELECT%20db%20%3D%20db_name(database_id)%2C%20name%2C%20size_gb%2C%20azure_disk_size_gb%20%3CBR%20%2F%3Efrom%20mi.master_files%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3ESum%20of%20the%20azure%20disk%20sizes%20should%20not%20exceed%2035TB%20-%20otherwise%20you%20will%20reach%20the%20azure%20storage%20limit%20errors.%20You%20can%20check%20total%20allocated%20azure%20storage%20space%20using%20the%20following%20query%3A%3C%2FP%3E%0A%3CPRE%3ESELECT%20storage_size_tb%20%3D%20SUM(azure_disk_size_gb)%20%2F1024.%20%0AFROM%20mi.master_files%3C%2FPRE%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3EUsing%20this%20information%2C%20you%20can%20find%20out%20how%20many%20additional%20files%20you%20can%20add%20on%20a%20managed%20instance%20(assuming%20that%20new%20file%20will%20be%20smaller%20than%20128GB)%3A%20%3C%2FFONT%3E%3C%2FP%3E%0A%3CPRE%3ESELECT%20remaining_number_of_128gb_files%20%3D%20%0A(35%20-%20ROUND(SUM(azure_disk_size_gb)%20%2F1024%2C0))%20*%208%20%0AFROM%20mi.master_files%3C%2FPRE%3E%0A%3CP%3EThis%20is%20important%20check%20because%20if%20this%20count%20became%20zero%2C%20you%20will%20not%20be%20able%20to%20add%20more%20files%20of%20database%20on%20the%20instance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-386234%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Aug%2020%2C%202018%20Azure%20SQL%20Database%20Managed%20Instance%20General%20Purpose%20is%20SQL%20Server%20implementation%20on%20Azure%20cloud%20that%20keeps%20all%20database%20files%20on%20Azure%20storage.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-386234%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerStorageEngine%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on MSDN on Aug 20, 2018
Azure SQL Database Managed Instance General Purpose (GP) is SQL Server implementation on Azure cloud that keeps all database files on Azure storage. In this post you will learn how Managed Instance General Purpose allocates disks in the storage layer at the back end and why this is important.

 

Please note this article does not apply to Business Critical edition of Managed Instance.

Azure SQL Database Managed Instance General Purpose tier separates compute and storage layers where the database files are placed on Azure Premium disks. Managed Instance uses pre-defined sizes of azure disks (128GB, 256GB, 512GB, etc.) for every file, so every file is placed on a single disk with the smallest size that is large enough to fit the file with the current file size.

Once you provision Managed Instance you have the following two storage limits:

 

  1. Managed Instance General Purpose user storage cannot exceed 8TB. Your max storage size cannot be greater than 8TB, and you are paying only for the amount of storage size that you choose in portal.
  2. Maximum of 280 data files on the General Purpose instance. This limitation is due to how Azure premium disk storage is allocated internally. 280 files placed on the smallest 128GB disk will reach beyond the 35TB of maximum internal Azure premium storage limit. Please note that this limit is internal to Azure storage under the hood, and that customers can still only use up to 8TB of storage for the Managed Instance.


When you create database files, they are allocated on Azure premium disks with sizes that are greater than the actual file size, so practically this is "internal fragmentation" of files. This is implemented because Azure premium disk storage offers fixed set of disk sizes, so Managed Instance tries to fit database files on a matching disk.

The number of data files per General Purpose Managed Instance cannot be greater than 280 files summing up to the maximum of 35TB of storage on Azure premium disks with internal fragmentation. If you reach this limit you might start getting errors even if you have not actually reached the user-defined Managed Instance storage limit of 8TB.

In this post, you will see some scripts that can help you to see are you reaching this storage limit.

First, we will create a schema and view that wraps standard sys.master_files view and returns the allocated disk size for every file:

CREATE SCHEMA mi; 
GO 
CREATE OR ALTER VIEW mi.master_files 
AS 
WITH mi_master_files AS 
( SELECT *, size_gb = CAST(size * 8. / 1024 / 1024 AS decimal(12,4)) 
FROM sys.master_files ) 
SELECT *, azure_disk_size_gb = IIF( 
database_id <> 2, 
CASE WHEN size_gb <= 128 THEN 128 
WHEN size_gb > 128 AND size_gb <= 256 THEN 256 
WHEN size_gb > 256 AND size_gb <= 512 THEN 512 
WHEN size_gb > 512 AND size_gb <= 1024 THEN 1024 
WHEN size_gb > 1024 AND size_gb <= 2048 THEN 2048 
WHEN size_gb > 2048 AND size_gb <= 4096 THEN 4096 
ELSE 8192 
END, NULL) 
FROM mi_master_files; 

Now we can see the size allocated for the underlying Azure Premium Disks for every database file:
SELECT db = db_name(database_id), name, size_gb, azure_disk_size_gb
from mi.master_files;

Sum of the azure disk sizes should not exceed 35TB - otherwise you will reach the azure storage limit errors. You can check total allocated azure storage space using the following query:

SELECT storage_size_tb = SUM(azure_disk_size_gb) /1024. 
FROM mi.master_files

Using this information, you can find out how many additional files you can add on a managed instance (assuming that new file will be smaller than 128GB):

SELECT remaining_number_of_128gb_files = 
(35 - ROUND(SUM(azure_disk_size_gb) /1024,0)) * 8 
FROM mi.master_files

This is important check because if this count became zero, you will not be able to add more files of database on the instance.