是否可以使用 DBCC SHRINKFILE 收缩链接服务器上的日志文件?

发布于 2024-09-15 07:29:13 字数 172 浏览 2 评论 0原文

我正在将大量数据从一个数据库归档到链接服务器上的另一个数据库。我正在从 MS sql server 2000 复制到 MS sql server 2005。 这涉及复制数百万条记录然后删除它们。这一切都是通过动态脚本发生的。我想在此过程中合并日志文件的收缩,但我无法使 DBCC SHRINKFILE 适用于链接服务器。这可能吗?

I am doing a large archival of data from one DB to another DB on a linked server. I am copying from MS sql server 2000 to MS sql server 2005.
This involves copying millions of records and then deleting them. This all happens via a dynamic script. I would like to incorporate the shrinking of the log file for this process, but I am unable to get the DBCC SHRINKFILE to work for the linked server. Is this even possible?

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

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

发布评论

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

评论(1

長街聽風 2024-09-22 07:29:13

您应该能够通过链接服务器调用 sp_executesql 来完成此操作:

EXEC [LINKED_SERVER].MyDatabase.dbo.sp_executesql
    @statement = N'DBCC SHRINKFILE(''LogFileName'',0)'

不过,您可能应该重新考虑自动收缩日志文件,特别是如果该脚本运行得如此频繁以至于您需要将其自动化。您最好备份日志或将恢复模式切换为简单,以便可以重用空间。 (如果它要恢复到相同的大小,您真的通过缩小它来完成任何事情吗?事实上,您可能会因无意中引入文件系统碎片而使事情变得更糟。)

我并不是说您永远不需要以编程方式缩小文件,但想要这样做通常表明存在其他问题 - 磁盘对于您的预期卷来说太小,您的恢复模式错误等。

You should be able to do it by calling sp_executesql through the linked server:

EXEC [LINKED_SERVER].MyDatabase.dbo.sp_executesql
    @statement = N'DBCC SHRINKFILE(''LogFileName'',0)'

You should probably rethink automatically shrinking the log file, though, especially if this script will be run so often that you need to automate it. You'll be better off backing up the log or switching the recovery model to Simple so you can reuse the space. (If it's going to grow back to the same size, did you really accomplish anything by shrinking it? In fact, you can make things worse by inadvertently introducing filesystem fragmentation.)

I'm not saying you never need to shrink a file programmatically, but wanting to do so is usually a sign something else is wrong -- the disk is too small for your expected volume, you have the wrong recovery model, etc.

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