简体   繁体   English

我应该在SQL Server 2000到2005数据库迁移后重建表索引

[英]Should I rebuild table indexes after a SQL Server 2000 to 2005 database migration

I'm tasked with doing a SQL Server 2000 to 2005 migration. 我的任务是进行SQL Server 2000到2005的迁移。 I will be doing a side-by-side migration. 我将进行并排迁移。

After restoring from a backup I plan to do the following: 从备份恢复后,我计划执行以下操作:

ALTER DATABASE <database_name> SET COMPATIBILITY_LEVEL = 90;

DBCC CHECKDB(<database_name>) WITH NO_INFOMSGS

DBCC UPDATEUSAGE(<database_name>) WITH NO_INFOMSGS

exec sp_updatestats ‘resample’

Should I rebuild table indexes before using DBCC UPDATEUSAGE and sp_updatestats? 我应该在使用DBCC UPDATEUSAGE和sp_updatestats之前重建表索引吗?

Have I missed anything obvious that should be executed after a migration? 我是否遗漏了迁移后应该执行的任何明显事项?

All help would be warmly up-voted. 所有帮助都将热烈投票。

Thanks 谢谢

There isn't much authoritative online material providing specifics on migration (beyond procedures aimed at merely ensuring the database structural integrity in the new/upgraded host). 没有太多权威的在线材料提供有关迁移的细节(除了旨在仅确保新/升级主机中的数据库结构完整性的程序之外)。 For this reason, and because this migration seems to be scheduled/planned event for you, I'd take the opportunity to rebuild all indexes, including clustered indexes . 出于这个原因,并且因为此迁移似乎是您的预定/计划事件,我将借此机会重建所有索引,包括聚簇索引

To some, this may seem "overkill", but what better opportunity of re-balancing and re-packing indexes/tables, providing a fresh fill-factor that is commensurate with the expected CRUD usage, and to generally assert the database's health in its new host. 对某些人来说,这看起来似乎“过度”,但更好的机会是重新平衡和重新打包索引/表格,提供与预期的CRUD使用量相称的新填充因子,并通常在其中确定数据库的健康状况。新主持人。

In practical terms, I would... 实际上,我会......

ALTER DATABASE <database_name> SET COMPATIBILITY_LEVEL = 90;

DBCC CHECKDB(<database_name>)
   -- WITH NO_INFOMSGS  (I'd take the messages, I'm curious by nature ;-)

Like you suggest, but then I'd rebuild all indexes on all/most tables even (maybe in particular...) on very big tables. 就像你建议的那样,但是我会在非常大的表上重建所有/大多数表上的所有索引(特别是......)。 To be sure, one should evaluate the time and relative risk involved with such an operation, but for most cases, even with databases in the 100+ million rows, the overall time overhead is in the order of a few hours, time well invested, for it may defer future index rebuilds. 可以肯定的是,应该评估这种操作所涉及的时间和相对风险,但是对于大多数情况,即使数据库在1亿多行中,总体时间开销大约为几小时,投入时间也很充足,因为它可能推迟未来的索引重建。 As to the risk factor, you seem to have a backup... 至于风险因素,你似乎有一个备份......

What goes without saying... When the underlying table has a clustered index, and if it desirable to rebuild it as well, do drop all other indexes before, lest a lot of time is wasted in updating the non-clustered index (without they being rebuilt in earnest), then of course recreate these non-clustered indexes. 毋庸置疑......当底层表有一个聚簇索引,并且还希望重建它时,请先删除所有其他索引,以免在更新非聚集索引时浪费大量时间(没有它们)正在认真重建 ),然后当然重新创建这些非聚集索引。

Depending on the number of tables and indexes in question, it may be profitable to write a few small Stored Procedures to automate the index dropping (and re-creating, although it may also be important to individually review the fill-factors, recompute and other parameter). 根据所讨论的表和索引的数量,编写一些小的存储过程来自动化索引丢弃(并重新创建,虽然单独查看填充因子,重新计算等等也可能很重要,这可能是有利可图的。参数)。

"Have I missed anything obvious that should be executed after a migration?" “我错过了迁移后应该执行的任何明显事项吗?”

  • Make sure you're running the latest SP of SS 2005. 确保你正在运行SS 2005的最新SP。
  • I'm surprised that you make no mention of having tested all your SPs and UDFs in SS 2005 to prove that they succeed in the same ways and fail predictably throughout. 我很惊讶您没有提及在SS 2005中测试过所有的SP和UDF,以证明它们以相同的方式成功并且在整个过程中无法预测。 This may take some time to do, but gives you a great chance to dramatically upgrade your system's robustness. 这可能需要一些时间,但为您提供了一个极大的机会来大幅提升系统的稳健性。

Addition to your list CheckDB before the database leaves SQL 2000 - you want to be as sure as possible no corruption from 2000 is brought over, if anyone started deallocating stuff in the system tables instead of using the proper commands will give you a mare once migrated. 在数据库离开SQL 2000之前加入你的列表CheckDB - 你希望尽可能确保2000年没有损坏,如果有人开始在系统表中释放东西而不是使用正确的命令,那么迁移后会给你一个母马。

If you rebuild the indexes then exec sp_updatestats 'resample' will give you worse statistics for your indexes since they would of already been updated by the rebuilds. 如果重建索引,那么exec sp_updatestats'resample'将为您的索引提供更糟糕的统计信息,因为它们已经由重建更新。 Additional stats added might well need to be updated, but do them individually, don't kill the index stats for them. 添加的其他统计信息可能需要更新,但要单独执行,不要删除它们的索引统计信息。

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

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