简体   繁体   English

如何在SQL Azure中找到最大数据库空间和已用数据库空间?

[英]How do I find the maximum database space and the used database space in SQL Azure?

In SQL Azure each database has a size limitation ( adjustable ). 在SQL Azure中,每个数据库都有大小限制( 可调 )。 In order for my service to not suddenly come to a halt I'd like to be able to programmatically find the current maximum size and current actually used space (and generate and alert once some threshold is reached). 为了使我的服务不会突然停止,我希望能够以编程方式找到当前的最大大小和当前实际使用的空间(并在达到某个阈值时生成并发出警报)。

Looks like sp_mstablespace can be used to solve this problem , but this stored procedure is not available in SQL Azure. 看起来sp_mstablespace可以用来解决此问题 ,但是此存储过程在SQL Azure中不可用。

How do I find the current maximum allowed size and current actually used space in a SQL Azure database? 如何在SQL Azure数据库中找到当前允许的最大大小和当前实际使用的空间?

You can calculate used space via dynamic management views (reference page here ): 您可以通过动态管理视图( 此处的参考页)来计算已用空间:

SELECT SUM(reserved_page_count)*8.0/1024
FROM sys.dm_db_partition_stats; 

While I don't think you can retrieve max size, it doesn't hurt to simply set your database to the largest size, since you're only billed for space you use. 虽然我不认为您可以检索最大大小,但是只需将数据库设置为最大大小就不会有什么坏处,因为您只需为使用的空间付费。 Having said that: If you're only in the sub-5GB range, it's best to go with Web edition. 话虽如此:如果您的容量不足5 GB,那么最好使用Web版。 If you're already at 10+ GB, there shouldn't be any harm setting max size to 150GB and then monitoring consumed size. 如果您已经拥有10+ GB的空间,那么将最大大小设置为150GB,然后监视消耗的大小应该不会有任何危害。

David has already pointed out how to find the current size of your database, if you want to know the maximum size of your database in MB, you need to run the following query in the database you're interested in: David已经指出了如何找到数据库的当前大小,如果您想知道数据库的最大大小(以MB为单位),则需要在您感兴趣的数据库中运行以下查询:

SELECT CONVERT(BIGINT, DATABASEPROPERTYEX('DatabaseOfInterestName', 'MaxSizeInBytes')) / 1024

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM