一个客户
问道:为什么我花了7个小时来备份我的数据库,却要用21个小时来还原?
可能的原因有很多。比如,你有个1TB的数据库,但是只储存了100GB的数据,那么备份的时候,只需要备份这100GB的数据。然而,在还原数据库的时候,你必须重构1TB的数据库,那将意味着大量的时间将被消耗。另一种情况是,你可能没有使用instant file initialization, 将文件预填零操作将会导致大量的写操作。
以下是一次还原操作的错误日志,这通常可以用来决定在备份/还原过程中,哪一步消耗了时间。
2008-01-23 08:38:40.42 spid52&">nbsp; Starting up database 'dbPerf_MAIN'.
2008-01-23 08:38:40.52 spid52 The database 'dbPerf_MAIN' is marked RESTORING and is in a state that does not allow recovery to be run.
2008-01-23 08:38:43.71 spid52 Starting up database 'dbPerf_MAIN'.
2008-01-23 08:38:46.82 Backup Restore is complete on database 'dbPerf_MAIN'. The database is now available.
2008-01-23 08:38:46.82 Backup Database was restored: Database: dbPerf_MAIN, creation date(time): 2008/01/16(14:04:58), first LSN: 647:4889:66, last LSN: 647:4918:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'c:\temp\dbperf_main.bak'}). Informational message. No user action required.
正如以前所提及的(https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=930079&SiteID=1), SQLServer确实有一套跟踪标志来为备份或者还原操作提供更详细的信息。
警告:跟踪标志应在微软SQL Server Support指导下使用。在这里仅作为讨论使用,将不会再后期版本中被支持。
以下的SQL Server 错误日志输出使用了跟踪标志3004来收集额外的信息。跟踪标志3605同样被使用来使输出进入错误日志。
我标亮了正常输出信息来使之更适于被阅读。阅读细节信息可以帮助你了解发生了什么。比如,停止全文搜索发生在你能够看到数据库被启动之前。使用时间戳和相关的信息可以帮助你了解一个标准的还原过程,以及决定哪里将是效率瓶颈。
dbcc traceon(3004, 3605, -1)
restore database dbPerf_MAIN from disk = 'c:\perf.bak' with replace, stats=1
2008-01-23 08:59:56.26 spid52 RestoreDatabase: Database dbPerf_MAIN
2008-01-23 08:59:56.26 spid52 Opening backup set
2008-01-23 08:59:56.31 spid52 Restore: Configuration section loaded
2008-01-23 08:59:56.31 spid52 Restore: Backup set is open
2008-01-23 08:59:56.31 spid52 Restore: Planning begins
2008-01-23 08:59:56.32 spid52 Halting FullText crawls on database dbPerf_MAIN
2008-01-23 08:59:56.32 spid52 Dismounting FullText catalogs
2008-01-23 08:59:56.32 spid52 X-locking database: dbPerf_MAIN
2008-01-23 08:59:56.32 spid52 Restore: Planning complete
2008-01-23 08:59:56.32 spid52 Restore: BeginRestore (offline) on dbPerf_MAIN
2008-01-23 08:59:56.40 spid52 Restore: PreparingContainers
2008-01-23 08:59:56.43 spid52 Restore: Containers are ready
2008-01-23 08:59:56.43 spid52 Zeroing C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\dbPerf_MAIN_log.LDF from page 1 to 17312 (0x2000 to 0x8740000)
2008-01-23 08:59:56.43 spid52 Restore: Restoring backup set
2008-01-23 08:59:56.43 spid52 Restore: Transferring data to dbPerf_MAIN
2008-01-23 08:59:58.55 spid52 Restore: Waiting for log zero on dbPerf_MAIN
2008-01-23 09:00:00.64 spid52 Zeroing completed on C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\dbPerf_MAIN_log.LDF
2008-01-23 09:00:00.70 spid52 Restore: LogZero complete
2008-01-23 09:00:00.97 spid52 FileHandleCache: 0 files opened. CacheSize: 12
2008-01-23 09:00:00.97 spid52 Restore: Data transfer complete on dbPerf_MAIN
2008-01-23 09:00:00.97 spid52 Restore: Backup set restored
2008-01-23 09:00:01.11 spid52 Starting up database 'dbPerf_MAIN'.
2008-01-23 09:00:01.15 spid52 The database 'dbPerf_MAIN' is marked RESTORING and is in a state that does not allow recovery to be run.
2008-01-23 09:00:01.15 spid52 Restore-Redo begins on database dbPerf_MAIN
2008-01-23 09:00:04.06 spid52 Rollforward complete on database dbPerf_MAIN
2008-01-23 09:00:04.09 spid52 Restore: Done with fixups
2008-01-23 09:00:04.09 spid52 Restore: Transitioning database to ONLINE
2008-01-23 09:00:04.09 spid52 Restore: Restarting database for ONLINE
2008-01-23 09:00:04.31 spid52 Starting up database 'dbPerf_MAIN'.
2008-01-23 09:00:05.32 spid52 FixupLogTail(progress) zeroing C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\dbPerf_MAIN_log.LDF from 0x6cf6c00 to 0x6cf8000.
2008-01-23 09:00:05.32 spid52 Zeroing C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\dbPerf_MAIN_log.LDF from page 13948 to 13960 (0x6cf8000 to 0x6d10000)
2008-01-23 09:00:05.32 spid52 Zeroing completed on C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\dbPerf_MAIN_log.LDF
2008-01-23 09:00:05.38 spid52 PostRestoreContainerFixups: running fixups on dbPerf_MAIN
2008-01-23 09:00:05.38 spid52 PostRestoreContainerFixups: fixups complete
2008-01-23 09:00:05.41 spid52 PostRestoreReplicationFixup for dbPerf_MAIN starts
2008-01-23 09:00:06.04 spid52 PostRestoreReplicationFixup for dbPerf_MAIN complete
2008-01-23 09:00:06.08 spid52 Restore: Database is restarted
2008-01-23 09:00:06.08 Backup Restore is complete on database 'dbPerf_MAIN'. The database is now available.
2008-01-23 09:00:06.08 spid52 Resuming any halted fulltext crawls
2008-01-23 09:00:06.08 spid52 Restore: Writing history records
2008-01-23 09:00:06.08 Backup Database was restored: Database: dbPerf_MAIN, creation date(time): 2008/01/16(14:04:58), first LSN: 647:4889:66, last LSN: 647:4918:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'c:\temp\dbperf_main.bak'}). Informational message. No user action required.
2008-01-23 09:00:06.10 spid52 Writing backup history records
2008-01-23 09:00:06.18 spid52 Restore: Done with MSDB maintenance
2008-01-23 09:00:06.18 spid52 RestoreDatabase: Finished