计算 SQL Azure 数据库大小

19

我如何计算 SQL Azure 数据库的当前大小?(不是最大大小限制)

多个地方(例如这里)建议使用以下 SQL:

SELECT SUM(reserved_page_count) * 8192
FROM    sys.dm_db_partition_stats

然而,当使用管理员登录执行此操作时,我会收到以下错误:

Msg 297, Level 16, State 1, Line 1
The user does not have permission to perform this action.

授予 database_user 查看数据库状态的权限; - RolandoCC
1个回答

40

这很可能是因为您正在数据库上运行查询。如果您正在使用SQL Server Management Studio,请先选择您的数据库(而不是主数据库),然后执行查询。这应该可以解决问题。哦,顺便说一下,如果想要以兆字节为单位显示大小,请尝试以下操作:

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

或者 您也可以通过 Windows Azure 管理门户检查数据库大小及其使用情况. enter image description here

来源:https://azure.microsoft.com/zh-cn/documentation/articles/sql-database-monitoring-with-dmvs/


1
微软官方参考页面:http://msdn.microsoft.com/zh-cn/library/windowsazure/ff394114.aspx - avs099
我正在使用来自CodePlex的迁移向导将我的SQL数据库移动到Azure https://sqlazuremw.codeplex.com/,但“使用概述”不可用。因为数据库是如此新,所以我使用了您的查询,它非常有效。谢谢! - JP Hellemons
仅供参考:(reserved_page_count * 8192) 是以千字节为单位的大小,因此将其转换为兆字节只需 (reserved_page_count * 8192) / 1024 即可。您的查询将返回以吉字节为单位的大小。 - David Ferenczy Rogožan
@avs099 官方参考页面现已移至https://azure.microsoft.com/zh-cn/documentation/articles/sql-database-monitoring-with-dmvs/。 - JKennedy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接