从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>DBCC checkDb('DataBaseName')</cmd>
- <err>Error 2508, Severity 16, level 3 : The In-row data RSVD page count for object "bMaterialIn79", index ID 0, partition ID 4563097419776, alloc unit ID 4563097419776(type In-row data) is incorrect. Run DBCC UPDATEUSAGE.</err>
- <err>Error 2508, Severity 16, level 3 : The In-row data RSVD page count for object "bMaterialIn93", index ID 0, partition ID 70442742317056, alloc unit ID 70442742317056(type In-row data) is incorrect. Run DBCC UPDATEUSAGE.</err>
- <msg>DBCC results for 'LibraryMS'.</msg>
- <msg>Service Broker Msg 9675, State 1: Message Types analyzed: 14.</msg>
- <msg>Service Broker Msg 9676, State 1: Service Contracts analyzed: 6.</msg>
- <msg>Service Broker Msg 9667, State 1: Services analyzed: 3.</msg>
- <msg>Service Broker Msg 9668, State 1: Service Queues analyzed: 3.</msg>
- <msg>Service Broker Msg 9669, State 1: Conversation Endpoints analyzed: 0.</msg>
- <msg>Service Broker Msg 9674, State 1: Conversation Groups analyzed: 0.</msg>
- <msg>Service Broker Msg 9670, State 1: Remote Service Bindings analyzed: 0.</msg>
- <msg>Service Broker Msg 9605, State 1: Conversation Priorities analyzed: 0.</msg>
- <msg>DBCC results for 'sys.sysrscols'.</msg>
- <msg>There are 6701 rows in 63 pages for object "sys.sysrscols".</msg>
- <msg>DBCC results for 'sys.sysrowsets'.</msg>
- <msg>There are 819 rows in 12 pages for object "sys.sysrowsets".</msg>
- <msg>DBCC results for 'sys.sysallocunits'.</msg>
- <msg>There are 848 rows in 17 pages for object "sys.sysallocunits".</msg>
- .................................................................................
- .................................................................................
- <msg>DBCC results for 'bMaterialIn79'.</msg>
- <msg>There are 1346 rows in 18 pages for object "bMaterialIn79".</msg>
- <msg>CHECKDB found 0 allocation errors and 1 consistency errors in table 'bMaterialIn79'(object ID 69627341).</msg>
- ...............................................................................
- ...............................................................................
- <msg>DBCC results for 'bMaterialIn93'.</msg>
- <msg>There are 2162 rows in 23 pages for object "bMaterialIn93".</msg>
- <msg>CHECKDB found 0 allocation errors and 1 consistency errors in table 'bMaterialIn93'(object ID 1074870946).</msg>
- <msg>CHECKDB found 0 allocation errors and 2 consistency errors in database 'DataBaseName'.</msg>
- <msg>DBCC execution completed. If DBCC printed error messages, contact your system administrator.</msg>
- </Exec>
对数据库执行DBCC CHECKDB('DataBaseName')得到的内容跟YourSQLDba的错误日志信息一致
- DBCC results for 'DataBaseName'.
- Service Broker Msg 9675, State 1: Message Types analyzed: 14.
- Service Broker Msg 9676, State 1: Service Contracts analyzed: 6.
- Service Broker Msg 9667, State 1: Services analyzed: 3.
- Service Broker Msg 9668, State 1: Service Queues analyzed: 3.
- Service Broker Msg 9669, State 1: Conversation Endpoints analyzed: 0.
- Service Broker Msg 9674, State 1: Conversation Groups analyzed: 0.
- Service Broker Msg 9670, State 1: Remote Service Bindings analyzed: 0.
- Service Broker Msg 9605, State 1: Conversation Priorities analyzed: 0.
- DBCC results for 'sys.sysrscols'.
- There are 6701 rows in 63 pages for object "sys.sysrscols".
- DBCC results for 'sys.sysrowsets'.
- There are 819 rows in 12 pages for object "sys.sysrowsets".
- ...................................................................
- ..................................................................
- DBCC results for 'bMaterialIn79'.
- Msg 2508, Level 16, State 3, Line 1
- The In-row data RSVD page count for object "bMaterialIn79", index ID 0, partition ID 4563097419776, alloc unit ID 4563097419776(type In-row data) is incorrect. Run DBCC UPDATEUSAGE.
- There are 1346 rows in 18 pages for object "bMaterialIn79".
- CHECKDB found 0 allocation errors and 1 consistency errors in table 'bMaterialIn79'(object ID 69627341).
- .....................................................................
- .....................................................................
- The In-row data RSVD page count for object "bMaterialIn93", index ID 0, partition ID 70442742317056, alloc unit ID 70442742317056(type In-row data) is incorrect. Run DBCC UPDATEUSAGE.
- There are 2162 rows in 23 pages for object "bMaterialIn93".
- CHECKDB found 0 allocation errors and 1 consistency errors in table 'bMaterialIn93'(object ID 1074870946).
- DBCC results for 'bMaterialApply40'.
- ....................................................................
- ....................................................................
- CHECKDB found 0 allocation errors and 2 consistency errors in database 'DataBaseName'.
- DBCC execution completed. If DBCC printed error messages, contact your system administrator.
分析原因:
这些错误提示数据页在保留空间中不正确的值,在SQL 2000中,这些错误也有可能是数据条目或者数据页的数目跟索引或表中记录的不一致所导致的。CheckDB 不会修复类似错误,在SQL 2005 中CheckDB只会给出一个警告信息。这不是什么严重的错误,按照提示运行DBCC UPDATEUSAGE行了,这通常发生在SQL 2000升级为2005/2008后,在SQL 2005/2008中一般不会遇到。刚好我这个数据库DataBaseName是从SQL 2000升级到SQL 2008,其实这确实不是一个什么严重错误,但是YourSQLDba意识到了“严重性”将数据库出于紧急模式,不能让系统或用户继续操作该数据库了,那 么接下来用DBCC UPDATEUSAGE 解决该问题。
- DBCC UPDATEUSAGE(LibraryMS,"dbo.bMaterialIn79");
- GO
- DBCC UPDATEUSAGE: Usage counts updated for table 'bMaterialIn79'(index 'bMaterialIn79', partition 1):
- USED pages(In-row Data): changed from (21) to (19) pages.
- RSVD pages(In-row Data): changed from (-107) to (73) pages.
- DBCC UPDATEUSAGE: Usage counts updated for table 'bMaterialIn79'(index 'PK_bMaterialIn79', partition 1):
- RSVD pages(In-row Data): changed from (8) to (17) pages.
- DBCC execution completed. If DBCC printed error messages, contact your system administrator.
- DBCC UPDATEUSAGE(LibraryMS,"dbo.bMaterialIn93");
- GO
- DBCC UPDATEUSAGE: Usage counts updated for table 'bMaterialIn93'(index 'bMaterialIn93', partition 1):
- USED pages(In-row Data): changed from (38) to (24) pages.
- RSVD pages(In-row Data): changed from (-18) to (49) pages.
- DBCC UPDATEUSAGE: Usage counts updated for table 'bMaterialIn93'(index 'PK_bMaterialIn93', partition 1):
- RSVD pages(In-row Data): changed from (16) to (17) pages.
- DBCC execution completed. If DBCC printed error messages, contact your system administrator.
关于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 解决该问题。
------------------------------------------------------------------------------------------------------------------------