简体   繁体   English

SQL Server sp_clean_db_free_space

[英]SQL Server sp_clean_db_free_space

I just want to ask if I can use the stored procedure sp_clean_db_free_space as part of preventive maintenance? 我只想问一下我是否可以将存储过程sp_clean_db_free_space用作预防性维护的一部分?

What are the pros and cons of this built in stored procedure? 内置存储过程的优缺点是什么? I just want to hear the inputs of someone who already uses this. 我只想听听已经使用此功能的人的意见。

Thank you 谢谢

You would typically not need to explicitly run this, unless you have specific reasons. 除非有特殊原因,否则通常无需显式运行此命令。

Quoting from SQL Server Books Online's page for sp_clean_db_free_space : 从SQL Server联机丛书的页面中引用sp_clean_db_free_space

Delete operations from a table or update operations that cause a row to move can immediately free up space on a page by removing references to the row. 从表中删除操作或导致行移动的更新操作可以通过删除对行的引用来立即释放页面上的空间。 However, under certain circumstances, the row can physically remain on the data page as a ghost record. 但是,在某些情况下,该行实际上可以作为幻像记录保留在数据页上。 Ghost records are periodically removed by a background process . 鬼记录会通过后台进程定期删除 This residual data is not returned by the Database Engine in response to queries. 响应查询,数据库引擎不会返回这些剩余数据。 However, in environments in which the physical security of the data or backup files is at risk, you can use sp_clean_db_free_space to clean these ghost records. 但是,在数据或备份文件的物理安全性受到威胁的环境中,可以使用sp_clean_db_free_space清除这些sp_clean_db_free_space记录。

Notice that SQL Server already has a background process to achieve the same result as sp_clean_db_free_space . 注意,SQL Server已经有一个后台进程来实现与sp_clean_db_free_space相同的结果。

The only reason you might wish to explicitly run sp_clean_db_free_space is if there is a risk that the underlying database files or backups can be compromised and analysed. 您可能希望显式运行sp_clean_db_free_space的唯一原因是,如果存在可能破坏和分析基础数据库文件或备份的风险。 In such cases, any data that has not yet been swept up by the background process can be exposed. 在这种情况下,可以暴露尚未被后台进程清除的任何数据。 Of course, if your system has been compromised in such a way, you probably also have bigger problems on your hands! 当然,如果您的系统受到这种破坏,那么您可能还会遇到更大的问题!

Another reason might be that you have a time-bound requirement that deleted data should not be retained in any readable form. 另一个原因可能是您有时间限制,要求删除的数据不应以任何可读形式保留。 If you have only a general requirement that is not time-bound, then it would be acceptable to wait for the regular background process to perform this automatically. 如果您只有不受时间限制的一般要求,那么可以等待常规的后台进程自动执行此操作。

The same page also mentions: 同一页还提到:

Because running sp_clean_db_free_space can significantly affect I/O activity, we recommend that you run this procedure outside usual operation hours. 因为运行sp_clean_db_free_space会严重影响I / O活动,所以建议您在正常运行时间之外运行此过程。

Before you run sp_clean_db_free_space, we recommend that you create a full database backup. 在运行sp_clean_db_free_space之前,建议您创建完整的数据库备份。

To summarize: 总结一下:

  • You'd use the sp_clean_db_free_space stored procedure only if you have a time-bound requirement that deleted data should not be retained in any readable form. 仅当您有时间限制要求删除的数据不应以任何可读形式保留时,才使用sp_clean_db_free_space存储过程。
  • Running sp_clean_db_free_space is IO intensive. 运行sp_clean_db_free_space大量IO。
  • Microsoft recommend a full database backup prior to this, which has its own IO and space requirements. Microsoft建议在此之前进行完整的数据库备份,这有其自身的IO和空间要求。

Take a look at this related question on dba.stackexchange.com: https://dba.stackexchange.com/questions/11280/how-can-i-truly-delete-data-from-a-sql-server-table-still-shows-up-in-notepad/11281 在dba.stackexchange.com上查看以下相关问题: https ://dba.stackexchange.com/questions/11280/how-can-i-truly-delete-data-from-a-sql-server-table- 仍然显示-上-在-记事本/ 11281

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

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