Cuando una base de datos se pone en estado In Recovery debemos saber que el Servidor SQL ya está realizando un proceso de recuperación de esa base de datos . Intentar arreglar el problema por nuestra cuenta puede dejar esa base de datos inservible. Por lo tanto a continuación se propone una consulta que mostrará el tiempo que falta para que el Servidor SQL termine de recuperar la base de datos afectada.
En servidores SQL 2005 o superior:
DECLARE @DBName VARCHAR(64)
SET @DBName = ‘databasename‘
DECLARE @ErrorLog AS TABLE([LogDate] CHAR(24), [ProcessInfo] VARCHAR(64), [TEXT] VARCHAR(MAX))
INSERT INTO @ErrorLog
EXEC sys.xp_readerrorlog 0, 1, ‘Recovery of database’, @DBName
SELECT TOP 10 [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
En servidores SQL 2012 o superior:
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 5 [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