删除行后留下的 FILESTREAM 文件

发布于 2024-08-09 03:13:02 字数 223 浏览 2 评论 0 原文

我已经在我的 SQL 2008 服务器上成功设置了 FILESTREAM;但是我注意到,即使我删除了包含 FILESTREAM 数据的行,物理数据文件似乎也没有被删除。

我所说的物理文件是指 SQLServer 托管目录中以唯一标识符作为文件名的文件,而不是添加到数据库中的原始文件。

有谁知道SQLServer最终是否会删除该文件?如果从数据库中删除了很多大文件,我希望能够快速回收空间,仅此而已。

I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed that even when I have deleted rows containing FILESTREAM data, the physical data file doesn't seem to get deleted.

By the physical file, I mean the file in SQLServer's managed directory with a uniqueidentifer as the filename not the original file added to the dbase.

Does anyone know if SQLServer will delete the file eventually? If there are a lot of large files removed from the dbase I'd expect to be able to reclaim the space quickly that's all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

巴黎夜雨 2024-08-16 03:13:03

FILESTREAM 数据受事务控制,因此不会立即删除。

相反,SQL Server 运行一个垃圾收集器,当确定旧数据最终被删除时,该垃圾收集器会清除旧数据。

来自文档

FILESTREAM 垃圾收集是由数据库检查点进程触发的后台任务。当生成足够的事务日志时,会自动运行检查点。有关详细信息,请参阅SQL Server 2008 联机丛书主题“CHECKPOINT 和日志的活动部分”(http://msdn.microsoft.com/en-us/library/ms189573.aspx)。鉴于 FILESTREAM 文件操作最少记录在数据库的事务日志中,因此生成的事务日志记录数量可能需要一段时间才能触发检查点进程并发生垃圾收集。如果这成为问题,您可以使用 CHECKPOINT 语句强制进行垃圾回收。

FILESTREAM data is subject to transaction control and therefore is not deleted instantly.

Instead, SQL Server runs a garbage collector which purges the old data when it is sure it had been ultimately deleted.

From the documentation:

FILESTREAM garbage collection is a background task that is triggered by the database checkpoint process. A checkpoint is automatically run when enough transaction log has been generated. For more information, see the SQL Server 2008 Books Online topic “CHECKPOINT and the Active Portion of the Log” (http://msdn.microsoft.com/en-us/library/ms189573.aspx). Given that FILESTREAM file operations are minimally logged in the database’s transaction log, it may take a while before the number of transaction log records generated triggers a checkpoint process and garbage collection occurs. If this becomes a problem, you can force garbage collection by using the CHECKPOINTstatement.

伊面 2024-08-16 03:13:03

不幸的是,使用

sp_filestream_force_garbage_collection

这只适用于> = SQL Server 2012

use

sp_filestream_force_garbage_collection

unfortunately this only works >= SQL Server 2012

清泪尽 2024-08-16 03:13:03

首先,您必须创建一个检查点 对于 垃圾收集器工作。删除行后,您可以运行此代码来删除不属于任何行的所有文件。

USE [DataBaseName]
GO

-- Create a checkpoint on current database
CHECKPOINT
GO 

-- Execute Garbage Collector after a checkpoint created
EXEC sp_filestream_force_garbage_collection  'DataBaseName'
GO

First you have to create a Checkpoint for the Garbage Collector work. After you Deleted rows you can run this code to eliminate all files that don't belong to any row.

USE [DataBaseName]
GO

-- Create a checkpoint on current database
CHECKPOINT
GO 

-- Execute Garbage Collector after a checkpoint created
EXEC sp_filestream_force_garbage_collection  'DataBaseName'
GO
星星的軌跡 2024-08-16 03:13:03
DELETE FROM tbl_XXX DECLARE @test CHECKPOINT @test = 0

在您的 SQL Server 中运行它
您还可以观察到文件被从文件系统中删除。

您可以设置执行删除操作后等待垃圾收集器从文件系统中清理文件的分钟或秒数。

DELETE FROM tbl_XXX DECLARE @test CHECKPOINT @test = 0

Run this in your SQL Server
and You can observe the file getting deleted from file system also.

You can set the the number of minutes or seconds to wait for the garbage collector to clean up the files from the filesystem after performing the deletion operation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文