Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

sql server - 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). 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.

How do I find the current maximum allowed size and current actually used space in a SQL Azure database?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. If you're already at 10+ GB, there shouldn't be any harm setting max size to 150GB and then monitoring consumed size.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...