从SQL SERVER 2000 上迁移了一个数据库到SQL SERVER 2008 R2上,暂且用DataBaseName代替迁移的真实的数据库名(后面的资料也会将数据库真实的名字用DataBaseName代替),迁移过程中也没有啥问题,配置了YourDataBase,作业“YourSQLDba_FullBackups_And_Maintenance”每天凌晨12点整运行,结果第一天晚上YourDatabase将数据库DataBaseName置于紧急模式,检查错误日志情况如下:
错误现象:
YourSQLDba对数据库做一致性检查时,发现有错误,所以它将该数据库置于紧急模式,具体内容如下所
查看YourSQLDba的具体错误日志信息
单击Action字段,看到的内容如下(太多内容,部分省略)
- <Exec>
- <ctx>yMaint.IntegrityTesting</ctx>
- <cmd>DBCCcheckDb('DataBaseName')</cmd>
- <err>Error 2508,Severity 16,level 3 :TheIn-rowdataRSVDpagecountforobject"bMaterialIn79",indexID 0,partitionID 4563097419776,allocunitID 4563097419776(typeIn-rowdata)isincorrect.RunDBCCUPDATEUSAGE.</err>
- <err>Error 2508,Severity 16,level 3 :TheIn-rowdataRSVDpagecountforobject"bMaterialIn93",indexID 0,partitionID 70442742317056,allocunitID 70442742317056(typeIn-rowdata)isincorrect.RunDBCCUPDATEUSAGE.</err>
- <msg>DBCCresultsfor'LibraryMS'.</msg>
- <msg>ServiceBrokerMsg 9675,State 1:MessageTypesanalyzed: 14.</msg>
- <msg>ServiceBrokerMsg 9676,State 1:ServiceContractsanalyzed: 6.</msg>
- <msg>ServiceBrokerMsg 9667,State 1:Servicesanalyzed: 3.</msg>
- <msg>ServiceBrokerMsg 9668,State 1:ServiceQueuesanalyzed: 3.</msg>
- <msg>ServiceBrokerMsg 9669,State 1:ConversationEndpointsanalyzed: 0.</msg>
- <msg>ServiceBrokerMsg 9674,State 1:ConversationGroupsanalyzed: 0.</msg>
- <msg>ServiceBrokerMsg 9670,State 1:RemoteServiceBindingsanalyzed: 0.</msg>
- <msg>ServiceBrokerMsg 9605,State 1:ConversationPrioritiesanalyzed: 0.</msg>
- <msg>DBCCresultsfor'sys.sysrscols'.</msg>
- <msg>Thereare 6701 rowsin 63 pagesforobject"sys.sysrscols".</msg>
- <msg>DBCCresultsfor'sys.sysrowsets'.</msg>
- <msg>Thereare 819 rowsin 12 pagesforobject"sys.sysrowsets".</msg>
- <msg>DBCCresultsfor'sys.sysallocunits'.</msg>
- <msg>Thereare 848 rowsin 17 pagesforobject"sys.sysallocunits".</msg>
- .................................................................................
- .................................................................................
- <msg>DBCCresultsfor'bMaterialIn79'.</msg>
- <msg>Thereare 1346 rowsin 18 pagesforobject"bMaterialIn79".</msg>
- <msg>CHECKDBfound 0 allocationerrorsand 1 consistencyerrorsintable'bMaterialIn79'(objectID 69627341).</msg>
- ...............................................................................
- ...............................................................................
- <msg>DBCCresultsfor'bMaterialIn93'.</msg>
- <msg>Thereare 2162 rowsin 23 pagesforobject"bMaterialIn93".</msg>
- <msg>CHECKDBfound 0 allocationerrorsand 1 consistencyerrorsintable'bMaterialIn93'(objectID 1074870946).</msg>
- <msg>CHECKDBfound 0 allocationerrorsand 2 consistencyerrorsindatabase'DataBaseName'.</msg>
- <msg>DBCCexecutioncompleted.IfDBCCprintederrormessages,contactyoursystemadministrator.</msg>
- </Exec>
对数据库执行DBCC CHECKDB('DataBaseName')得到的内容跟YourSQLDba的错误日志信息一致
- DBCCresultsfor'DataBaseName'.
- ServiceBrokerMsg 9675,State 1:MessageTypesanalyzed: 14.
- ServiceBrokerMsg 9676,State 1:ServiceContractsanalyzed: 6.
- ServiceBrokerMsg 9667,State 1:Servicesanalyzed: 3.
- ServiceBrokerMsg 9668,State 1:ServiceQueuesanalyzed: 3.
- ServiceBrokerMsg 9669,State 1:ConversationEndpointsanalyzed: 0.
- ServiceBrokerMsg 9674,State 1:ConversationGroupsanalyzed: 0.
- ServiceBrokerMsg 9670,State 1:RemoteServiceBindingsanalyzed: 0.
- ServiceBrokerMsg 9605,State 1:ConversationPrioritiesanalyzed: 0.
- DBCCresultsfor'sys.sysrscols'.
- Thereare 6701 rowsin 63 pagesforobject"sys.sysrscols".
- DBCCresultsfor'sys.sysrowsets'.
- Thereare 819 rowsin 12 pagesforobject"sys.sysrowsets".
- ...................................................................
- ..................................................................
- DBCCresultsfor'bMaterialIn79'.
- Msg 2508,Level 16,State 3,Line 1
- TheIn-rowdataRSVDpagecountforobject"bMaterialIn79",indexID 0,partitionID 4563097419776,allocunitID 4563097419776(typeIn-rowdata)isincorrect.RunDBCCUPDATEUSAGE.
- Thereare 1346 rowsin 18 pagesforobject"bMaterialIn79".
- CHECKDBfound 0 allocationerrorsand 1 consistencyerrorsintable'bMaterialIn79'(objectID 69627341).
- .....................................................................
- .....................................................................
- TheIn-rowdataRSVDpagecountforobject"bMaterialIn93",indexID 0,partitionID 70442742317056,allocunitID 70442742317056(typeIn-rowdata)isincorrect.RunDBCCUPDATEUSAGE.
- Thereare 2162 rowsin 23 pagesforobject"bMaterialIn93".
- CHECKDBfound 0 allocationerrorsand 1 consistencyerrorsintable'bMaterialIn93'(objectID 1074870946).
- DBCCresultsfor'bMaterialApply40'.
- ....................................................................
- ....................................................................
- CHECKDBfound 0 allocationerrorsand 2 consistencyerrorsindatabase'DataBaseName'.
- DBCCexecutioncompleted.IfDBCCprintederrormessages,contactyoursystemadministrator.
分析原因:
这些错误提示数据页在保留空间中不正确的值,在SQL 2000中,这些错误也有可能是数据条目或者数据页的数目跟索引或表中记录的不一致所导致的。CheckDB 不会修复类似错误,在SQL 2005 中CheckDB只会给出一个警告信息。这不是什么严重的错误,按照提示运行DBCC UPDATEUSAGE行了,这通常发生在SQL 2000升级为2005/2008后,在SQL 2005/2008中一般不会遇到。刚好我这个数据库DataBaseName是从SQL 2000升级到SQL 2008,其实这确实不是一个什么严重错误,但是YourSQLDba意识到了“严重性”将数据库出于紧急模式,不能让系统或用户继续操作该数据库了,那么接下来用DBCC UPDATEUSAGE 解决该问题。
- DBCCUPDATEUSAGE(LibraryMS,"dbo.bMaterialIn79");
- GO
- DBCCUPDATEUSAGE:Usagecountsupdatedfortable'bMaterialIn79'(index'bMaterialIn79',partition 1):
- USEDpages(In-rowData):changedfrom (21)to (19)pages.
- RSVDpages(In-rowData):changedfrom (-107)to (73)pages.
- DBCCUPDATEUSAGE:Usagecountsupdatedfortable'bMaterialIn79'(index'PK_bMaterialIn79',partition 1):
- RSVDpages(In-rowData):changedfrom (8)to (17)pages.
- DBCCexecutioncompleted.IfDBCCprintederrormessages,contactyoursystemadministrator.
- DBCCUPDATEUSAGE(LibraryMS,"dbo.bMaterialIn93");
- GO
- DBCCUPDATEUSAGE:Usagecountsupdatedfortable'bMaterialIn93'(index'bMaterialIn93',partition 1):
- USEDpages(In-rowData):changedfrom (38)to (24)pages.
- RSVDpages(In-rowData):changedfrom (-18)to (49)pages.
- DBCCUPDATEUSAGE:Usagecountsupdatedfortable'bMaterialIn93'(index'PK_bMaterialIn93',partition 1):
- RSVDpages(In-rowData):changedfrom (16)to (17)pages.
- DBCCexecutioncompleted.IfDBCCprintederrormessages,contactyoursystemadministrator.
关于DBCC UPDATEUSAGE的MSDN解释如下:
-----------------------------------------------------------------------------------------------------------------------
备注
DBCC UPDATEUSAGE 将针对表或索引中的每个分区更正行、已用页、保留页、叶级页和数据页的计数。如果系统表中没有错误,则 DBCC UPDATEUSAGE 不返回数据。如果发现错误,并对其进行更正,同时没有使用 WITH NO_INFOMSGS,DBCC UPDATEUSAGE 将返回系统表中更新的行和列。
使用 DBCC UPDATEUSAGE 同步空间使用计数器。因为 DBCC UPDATEUSAGE 在大型表或大型数据库中运行可能会需要一些时间,所以通常只在怀疑 sp_spaceused 返回的值不正确时使用。sp_spaceused 在返回表或索引的空间信息之前接受可选参数以运行 DBCC UPDATEUSAGE。
升级数据库
在 SQL Server 的早期版本中,用于表和索引行计数以及页计数的值可能不正确。根据 SQL Server 2005 之前的版本创建的数据库可能包含错误的计数。因此,我们建议在升级之后运行 DBCC UPDATEUSAGE,以便更正所有的无效计数。
DBCC CHECKDB 已得到增强,可以检测页计数或行计数变为负值的情况。检测到上述问题后,DBCC CHECKDB 的输出会包含一个警告和一个建议,建议运行 DBCC UPDATEUSAGE 解决该问题。
------------------------------------------------------------------------------------------------------------------------