简体   繁体   English

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

[英]Is it possible to shrink a log file on a linked server using 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. 我正在从MS sql server 2000复制到MS sql server2005。这涉及到复制数百万条记录,然后删除它们。 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. 我想为此过程合并日志文件的缩小,但是我无法使DBCC SHRINKFILE用于链接服务器。 Is this even possible? 这有可能吗?

You should be able to do it by calling sp_executesql through the linked server: 您应该能够通过链接服务器调用sp_executesql来做到这一点:

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. 我并不是说您永远不需要以编程方式收缩文件,但通常这样做是一个信号,表明其他问题出了错-磁盘对于您的预期卷而言太小,恢复模型错误,等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM