atwork.blog

news and infos about microsoft, technology, cloud and more

Get the size of a SQL Azure database quickly

To get the size of a database, there are multiple ways. TSQL is one of the fastest methods. Here's how.

You often see querying the sys.dm_db_partition_stats DMV, and looking at the reserved_page_count column. Here's my slightly adapted query: First open a new query in the database you want to check, then execute the following statement to get the size in Gigabytes.

SELECT (SUM(reserved_page_count) * 8192) / 1024 / 1024 / 1024.0 AS DbSizeInGB
FROM sys.dm_db_partition_stats

image

Kindly, this is the same number, the Azure portal delivers, here the database size is (rounded) 6.06 GB. Additionally, the database overview menu informs about more interesting database properties and statistics.

image

See more at Monitoring Azure SQL Database using dynamic management views (find more useful queries there as well) and at Determining Database Size in Azure SQL Database V12.

Just to mention: The database size is not the same as for backups. When exporting the Data-tier to a .bacpac file, the database backup is just about 265 MB. Well packed!

image

(Another database with a database size of 0.10GB exported a 6.3MB small .bacpac file...)

So, the TSQL select does a good job for a quick database size overview.

Loading