ILearnable .Net

April 22, 2013

Sql Server In Recovery

Filed under: Uncategorized — andreakn @ 10:04

So, you just did something potentially stupid.

You became impatient while Sql Server was churning away at something and took forever to do a simple small little thing which should take no time at all. 

Maybe you reset the sql server service, maybe you reset the entire machine trying to free up the hangup, 

And you reward was the dreaded “(In Recovery)” suffix to your databases name.

….. nothing works, you can’t even query the DB… And suddenly teammates or customers ask you … HOW LONG UNTIL IT IS FIXED?!!

 

Instead of answering “I don’t know” or “everything comes to he who waits” you could try to  execute this little query

—————-

DECLARE @DBName VARCHAR(64) = ‘your_database_name_here’
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

——————

which should give you an inkling on the time remaining. (though to be quite honest it is not very accurate, the last percent seems to take a long time to resolve)

(thanks http://timlaqua.com/2009/09/determining-how-long-a-database-will-be-in-recovery-sql-server-2008/ for showing me the procedure! )

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: