如何清除 SQL 服务器的磁盘 space?

How do I clear disk space for SQL Server?

我是 运行 SQL Windows 10 的服务器。我在最近的所有查询中遇到以下两个错误之一:

The transaction log for database 'MyDB' is full due to 'ACTIVE_TRANSACTION'.

An error occurred while executing batch. Error message is: There is not enough space on the disk.

我已经尝试 DBCC SQLPERF('logspace') 分析磁盘 space。尝试按照建议 here. I do not anticipate being able to resolve the issue by shrinking the log file 执行查询后,数据库的日志很少 space。我尝试了 CREATE DATABASE,然后

SELECT * 
INTO new_db.table 
FROM old_db.table

出现以下错误:

Msg 1101, Level 17, State 12, Line 2
Could not allocate a new page for database 'new_db' because of insufficient disk space in filegroup 'PRIMARY'. Create the necessary space by dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.

我已经从 C:\Users\username\AppData\Local\Temp 中删除了日志文件,但出现了同样的异常。我还清理了硬盘驱动器和回收站中的文件,并对硬盘驱动器进行了碎片整理。我尝试将查询结果的路径调整到不同的目录(工具>选项>查询结果)。我还从数据库中删除了一些表,退出 SQL 服务器并重新连接,以及关闭我的计算机并重新启动它。

首先要了解的是 recovery mode 数据库使用的是哪种类型。

如果您处于 FULL 恢复模式,定期备份是不够的。您必须经常(每 20 分钟一次,甚至更快)事务日志备份Sql 服务器将 永远不会 回收事务日志,除非你这样做, 它将继续增长直到你 运行出自 space.

在您拥有 运行 事务日志备份后,您应该能够缩小日志文件并回收该磁盘 space。

如果您未处于 FULL 恢复模式,您可以在 Sql Server management studio 中手动清除或扩展事务日志。