SQLSERVER 2012

来源:互联网 发布:电脑上的健身软件 编辑:程序博客网 时间:2024/06/06 04:55

1.Ghost Cleanup 进程功能

Deletes 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.


Ghost Cleanup 进程通常在服务重启后运行的,主要作用:

1)清理在聚集表下,记录被删除后形成的ghost记录。

当在聚集索引下删除记录,并没有真正的删除只是标记为ghost记录,这样删除会变得更快,回滚只需要撤销标记。当事务提交后后台有ghost清理程序来清理这些被标记为ghost记录。并且会保留最后一个数据页的最有一条ghost记录以免页没释放。

当记录被删除会在pfs上标记ghost,在数据页头上也会标记。但是pfs上的标记并不会通知处理程序处理。只有到下一次扫描到这个页时才会处理,或者等到每5秒一次的清理进程激活,清理进程就会扫描pfs页,并对ghost页处理。若没有需要清理的了就跳入下一个数据库。若这次扫描没有发现有ghost记录,那么会设置上一个标记,下5秒唤醒就跳过这个数据库。

Reference:https://www.sqlskills.com/blogs/paul/inside-the-storage-engine-ghost-cleanup-in-depth/


2.Ghost Cleanup 进程如何屏蔽

在 MSSQL 的启动服务中增加 -t 6651 trace可以临时终止GHOST Cleanup的对日志文件的读取和清理操作。


或者: DBCC TRACEOFF(661,-1--在全局范围关闭ghost清理工具


3.Ghost Cleanup 进程处理案例

3.1 DBCC checkdb发现大量Transaction log 报错

....

page (1:2287922) does not match the previous page (1:226625) that the parent (4:1312990),
DBCC results for 'LOG'.
There are 42547680 rows in 4391675 pages for object "LOG".
CHECKDB found 0 allocation errors and 38 consistency errors in table 'LOG' (object ID 2021582240).


3.2 使用DBCCCHECKTABLE('Table_name',repair_rebuild) 将问题 Table 修复

3.3 由于本次问题发生在索引上,所以才去重新导出数据到新表的方法并重建索引解决。