gpt4 book ai didi

sql-server - 减少 Azure SQL 数据库大小

转载 作者:行者123 更新时间:2023-12-04 13:36:45 25 4
gpt4 key购买 nike

我正在尽最大努力删除行并重建索引,但数据库的大小增长得非常快,我看不到操作的效果。

造成这种情况的原因是什么?除了行删除和索引重建之外,还有其他方法可以减小数据库的大小吗?

非常感谢

最佳答案

请运行以下特殊存储过程并让我们知道哪个数据库文件正在变大。

sp_helpfile

如果日志文件变大,请运行以下语句来恢复空间日志。

DBCC SHRINKFILE (log, 0)

如果数据文件(而不是日志文件)的大小正在增加,请使用下面的查询来了解哪些表消耗的空间最多,并从那里开始调查。

select 
o.name,
max(s.row_count) AS 'Rows',
sum(s.reserved_page_count) * 8.0 / (1024 * 1024) as 'GB',
(8 * 1024 * sum(s.reserved_page_count)) / (max(s.row_count)) as 'Bytes/Row'
from sys.dm_db_partition_stats s, sys.objects o
where o.object_id = s.object_id
group by o.name
having max(s.row_count) > 0
order by GB desc

下面的查询还为您提供了每个索引的大小。

select  
o.Name,
i.Name,
max(s.row_count) AS 'Rows',
sum(s.reserved_page_count) * 8.0 / (1024 * 1024) as 'GB',
(8 * 1024* sum(s.reserved_page_count)) / max(s.row_count) as 'Bytes/Row'
from
sys.dm_db_partition_stats s,
sys.indexes i,
sys.objects o
where
s.object_id = i.object_id
and s.index_id = i.index_id
and s.index_id >0
and i.object_id = o.object_id
group by i.Name, o.Name
having SUM(s.row_count) > 0
order by GB desc

关于sql-server - 减少 Azure SQL 数据库大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45829322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com