当前位置:网站首页>sqlserver可用空间过大,回收未用空间
sqlserver可用空间过大,回收未用空间
2022-04-22 19:22:00 【平山CP3】
背景:阿里云RDS sqlserver2008数据库,因为错误操作,导致一个表插入大量数据,导致表内存,数据库内存超限,并产生自动锁。
解决:
1.查明原因后,赶紧停止错误操作,因为这个表数据意义不大,所以直接使用trancate语句直接清除该表数据
2.清除后,自动锁解除。但是存储空间还是没下去
3.产生疑问,到底是什么占用存储空间?
4.查看数据库大小:
use [$DB]
go
sp_spaceused @updateusage=N'true'

发现unallocated_space(未用空间)占比很大
5.网上看到一些回收的语句,但是还是小心点咨询了一下阿里云工单。售后工程师很认真的给了我回收语句。dbcc shrinkfile(N'testdb',0,truncateonly) 但是并没有效果。
6.又一次询问,给了新的语句。
--1.查看数据库总空间,已用空间,未用空间,使用率
USE $DB
GO
SELECT a.name as 逻辑文件名, size/128 [totalspace文件大小(兆)],
FILEPROPERTY(a.name, 'SpaceUsed')/128 [usedspace已用空间(兆)],
size/128 - FILEPROPERTY(a.name, 'SpaceUsed')/128 [未用空间(兆)],
FILEPROPERTY(a.name, 'SpaceUsed')*100.0/size [使用率(%)]
FROM sys.database_files a cross join (select recovery_model_desc, log_reuse_wait,log_reuse_wait_desc,is_auto_shrink_on from sys.databases where name=DB_NAME())b
WHERE type=0
--2.进行回收
declare @usedspace int ,@totalspace int
select @usedspace= xxx,@totalspace =yyy
while @totalspace> @usedspace
begin
set @totalspace= @totalspace-5 *1024
DBCC SHRINKFILE( 逻辑文件名,@totalspace )
end
--逻辑文件名,usedspace,totalspace从1中的结果集获取
这样回收后,未用空间终于降下去了,使用率从1%回到了40%。当然回收前进行一次全量备份还是必须的。
感谢阿里云,自己记录一下,也再去学些一下数据库空间的维护。
版权声明
本文为[平山CP3]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_33277597/article/details/103287712
边栏推荐
猜你喜欢

postman 测试 Array、List、Map 入参 API 正确姿势

Understanding of string constant pool and intern method

System Analyst - paper writing framework construction

深开鸿与亿晟科技签署合作协议,携手构建商显行业新生态

Network security -- the use of burp suite packet capture tool

LeetCode_343 整数拆分

Solution for C10K scenario of ICBC distributed service

uniapp商品分类选项卡

2路CAN/CAN FD 数据记录诊断仪为企业解决偶发性错误难点

【AI视野·今日NLP 自然语言处理论文速览 第三十三期】Thu, 21 Apr 2022
随机推荐
How to build the campus running platform?
【面试普通人VS高手系列】请说一下网络四元组
工商银行分布式服务C10K场景的解决方案
LeetCode 41. 缺失的第一个正数
System Analyst - paper writing framework construction
从零开始学安卓(kotlin)六——数据持久化
关于字符串常量池,intern方法的理解
Leetcode prefix and - question set
Where is the cut file? How to recover the lost file cut? Just 3 steps
Huawei equipment configuration policy routing to the side hanging firewall
.net core minimal api 上传文件
什么是 SAML 断言?
webrtc+turn+peerconnection_server测延时
mysql查询带序列号
Can fire doors be tested according to en 1634-1?
WebRTC:Mesh/MCU/SFU三种通信架构
The research group of Shenzhen University issued the evaluation report on sustainable development of Shenzhen (2016-2021)
ReDet 代码逐行解读
C#之委托
Can deleted photos be restored? 3 tips to restore deleted photos