当一个DB处于 In Recovery 状态时,用户是不能访问的,如果Recovery时间很长,那么对一个DBA来说,等待的过程是虐心的,DBA需要知道剩余的还原时间。如何预测一个DB从In Recovery 状态,还原到正常Online状态所需的时间? 虽然SQL Server 没有直接给出答案,但是,可以通过Recovery的历史记录来预测。
DECLARE @DBName VARCHAR(64) = ‘databasename‘ DECLARE @ErrorLog AS TABLE([LogDate] CHAR(24), [ProcessInfo] VARCHAR(64), [TEXT] VARCHAR(MAX)) INSERT INTO @ErrorLog EXEC master..sp_readerrorlog 0, 1, ‘Recovery of database‘, @DBName SELECT TOP 11 [LogDate] ,SUBSTRING([TEXT], CHARINDEX(‘) is ‘, [TEXT]) + 4,CHARINDEX(‘ complete (‘, [TEXT]) - CHARINDEX(‘) is ‘, [TEXT]) - 4) AS PercentComplete ,CAST(SUBSTRING([TEXT], CHARINDEX(‘approximately‘, [TEXT]) + 13,CHARINDEX(‘ seconds remain‘, [TEXT]) - CHARINDEX(‘approximately‘, [TEXT]) - 13) AS FLOAT)/60.0 AS MinutesRemaining ,CAST(SUBSTRING([TEXT], CHARINDEX(‘approximately‘, [TEXT]) + 13,CHARINDEX(‘ seconds remain‘, [TEXT]) - CHARINDEX(‘approximately‘, [TEXT]) - 13) AS FLOAT)/60.0/60.0 AS HoursRemaining ,[TEXT] FROM @ErrorLog ORDER BY [LogDate] DESC
引用于:
determining-how-long-a-database-will-be-in-recovery-sql-server-2008
时间: 2024-12-20 23:30:55