我遇到SQL Server问题我无法执行任何查询,因为托管数据库的硬盘已满。 我尝试使用MS SMS中的“Shrink”功能缩小数据库但由于磁盘空间已满而无法正常工作。
如何在不崩溃数据库的情况下截断日志,还缩小大小?
我也尝试过以下
USE myDatabaseName;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE myDatabaseName
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (myDatabaseName_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE myDatabaseName
SET RECOVERY FULL;
GO
但出现以下错误
Msg 3023, Level 16, State 3, Line 2
Backup and file manipulation operations (such as ALTER DATABASE ADD FILE) on a database must be serialized. Reissue the statement after the current backup or file manipulation operation is completed.
Msg 5069, Level 16, State 1, Line 2
ALTER DATABASE statement failed.
由于
答案 0 :(得分:2)
BACKUP LOG LogName
WITH TRUNCATE_ONLY;
WITH_TRUNCATEONLY
已被删除,因此您应将恢复模式切换为简单并恢复为执行相同的操作。
ALTER DATABASE DatabaseName
SET RECOVERY SIMPLE;
之后,请不要忘记重新启动原始恢复模式!
仅仅因为你截断了日志,这并不意味着磁盘上的文件大小已经改变了。
要减少日志的文件大小,您需要发出以下命令
DBCC SHRINKFILE (DatabaseLogLogicalName, 1);
答案 1 :(得分:1)