今天遇到了一个关于数据库一致性错误的案例。海外工厂的一台SQL Server 2005(9.00.5069.00 Standard Edition)数据库在做DBCC CHECKDB的时候出现了一致性错误,下面总结一下处理过程。具体的一致性错误信息如下所示:
Msg 8992, Level 16, State 1, Line 1
Check Catalog Msg 3853, State 1: Attribute (referenced_major_id=248841561,referenced_minor_id=6) of row (class=0,object_id=440842245,column_id=0,referenced_major_id=248841561,referenced_minor_id=6) in sys.sql_dependencies does not have a matching row (object_id=248841561,column_id=6) in sys.columns.
Msg 8992, Level 16, State 1, Line 1
Check Catalog Msg 3853, State 1: Attribute (referenced_major_id=264841618,referenced_minor_id=7) of row (class=0,object_id=440842245,column_id=0,referenced_major_id=264841618,referenced_minor_id=7) in sys.sql_dependencies does not have a matching row (object_id=264841618,column_id=7) in sys.columns.
CHECKDB found 0 allocation errors and 2 consistency errors not associated with any single object.
DBCC results for ‘sys.sysrowsetcolumns‘.
Msg 2508, Level 16, State 1, Line 1
The In-row data USED page count for object "GRNPGDetail", index ID 0, partition ID 60321137623040, alloc unit ID 60321137623040 (type In-row data) is incorrect. Run DBCC UPDATEUSAGE.
关于第三个一致性错误,我之前多篇博客都介绍过这种类型的一致性错误,需要使用DBCC UPDATEUSAGE,该命令可以针对表或索引中的每个分区更正行、已用页、保留页、叶级页和数据页的计数。DBCC UPDATEUSAGE命令报告目录视图中的页数和行数错误并进行更正。这些错误可能导致sp_spaceused 系统存储过程返回不正确的空间使用报告。此处略过。
下面我们来看看下面这个一致性错误,从类型上,是属于元数据损坏(metadata corruption)。但是这个案例呢,又有点特别,跟我之前遇到SQL Server元数据损坏(metadata corruption)修复案例不同,我们先来看看分析过程
首先,通过object_id找到这三个对象,然后我们通过错误信息,可以判断sys.sql_dependencies里面引用的对象,发现在sys.columns里面不存在这行记录(object_id=248841561,column_id=6;object_id=264841618,column_id=7 ), 如下截图所示,确实没有找到(object_id=248841561,column_id=6;object_id=264841618,column_id=7 )的记录。
Msg 8992, Level 16, State 1, Line 1
Check Catalog Msg 3853, State 1: Attribute (referenced_major_id=248841561,referenced_minor_id=6) of row (class=0,object_id=440842245,column_id=0,referenced_major_id=248841561,referenced_minor_id=6) in sys.sql_dependencies does not have a matching row (object_id=248841561,column_id=6) in sys.columns.
然后分析存储过程“zzzPrcUnallocationAgingSM_not used”(其实看这个存储过程命名,就知道这个存储过程废弃了,我们有些开发人员喜欢这样将一个存储过程标记为废弃了),研究分析发现,代码里面视图VW_SMAllocatedQty有个字段FactoryPoNo,而实际上,视图已经没有了这个字段,所以才会报这个一致性错误,只要注释掉这一行或删除这个存储过程,问题就解决了,DBCC CHEKDB检查,就会发现不存在一致性错误了。
原文地址:https://www.cnblogs.com/kerrycode/p/10254467.html