5

I have a database that is stuck in recovery mode for few days already. There are multiple threads about this, but the solutions there don't work for me.

Here is what I tried already:

RESTORE DATABASE [DBNAME] WITH RECOVERY 
Error: Exclusive access could not be obtained because the database is in use.

ALTER DATABASE [DBNAME] SET OFFLINE WITH ROLLBACK IMMEDIATE
Error: ALTER DATABASE failed because a lock could not be placed on database 'DBNAME'  
I get the same error when trying to set the db to SINGLE_USER

exec sp_who2 --> nothing that contains my database, so nothing that I can kill  
(Or I need to look for something else ??)

I can't just stop the SQL-service, because it contains too many databases that can't go down.

Who knows what I can do to get the database out of recovery mode? At both the primary and mirror location is the database state 'In recovery'.

UPDATE

I found a process in sp_who2 with command DB STARTUP.

At sys.dm_tran_locks, I see this session has a resource_database_id for the database that is in recovery, so this keeps the database locked. Anyone knows how to fix this without stopping SQL Server?

0

8 Answers 8

6

Restart the db mirroring end point:

--To stop 
ALTER ENDPOINT<Endpoint Name> STATE=STOPPED

--To start
ALTER ENDPOINT<Endpoint Name> STATE=STARTED

TECH note: if there are multiple databases, not just the one in error, then stopping and starting the enpoint affects all the databases on that endpoint. This can cause problems on a production system like SharePoint. To fix, go the other mirrored database server and enter the same commands: ALTER ENDPOINT STATE=STOPPED ALTER ENDPOINT STATE=STARTED

How to find the name of the end point? select * from sys.endpoints <- works for SQL 2012 The name will be of " type=4 " for mirroring.

1

I did this and waited.

ALTER DATABASE <datbasename>  SET PARTNER OFF;

it actually worked and I could run:

RESTORE DATABASE  <datbasename>  WITH RECOVERY;
0

Do you mind restoring from a backup?

You could try to use KILL on the session, but that might mess up the database integrity.

3
  • I agree with Nabil. You probably need to KILL the session on the Primary database set the database to SINGLE_USER and then restore using backups. Do the samething on the mirror and then setup your mirroring session again.
    – KenWilson
    Commented Jan 31, 2014 at 16:28
  • Already tried that, but I can't kill the process, error: "Only user processes can be killed." Commented Jan 31, 2014 at 16:30
  • 1
    Have you tried ALTER DATABASE <database_name> SET PARTNER OFF to turn off mirroring?
    – KenWilson
    Commented Jan 31, 2014 at 16:37
0

You might just be at that point where you need to failover and schedule an outage/wait it out.

Not the ideal solution, but it happens :/

0

When you see any database is in restoring mode, in SQL Server 2014 try to execute the following statement from master database.

restore database <dbname> with recovery

enter image description here

0

Today I have faced same problem. while configuring mirroring in SQL Server 2012 I observed that my mirror database status is in recovery mode. What I did is

alter database database_name set partner off

Now my mirror database status is Restoring mode.

0

Following worked for me on the Principal Server.

ALTER DATABASE <datbasename>  SET PARTNER OFF;
RESTORE DATABASE  <datbasename>  WITH RECOVERY;

Unable to get the database out of "in recovery" state on the mirrored box. Tried to: drop the database put it in emergency mode put it in single user mode put it offline

nothing worked, got following errors:

"Only user processes can be killed. blah blah" "Database is in use blah blah"

I have stopped & started SQL Server service and "Mirroring Endpoint" on the mirrored instance but didn't fix the issue. Still showing the database "in recovery" state.

Solution: I have stopped SQL Server service and deleted the log (.ldf) file of the database. Started SQL Server service and surprisingly it worked; the database was online. I have dropped the database and reconfigured mirroring.

-1

Case: Accidently When u run below command on Principal server instead of mirror server: alter database 'Database_Name' set partner off

After running above command your DB goes in [mirror, disconnected] State on mirror server.

Resolution:

Step 1:Run below query on mirror exec sp_resetstatus 'Database_Name'

Step 2: After running below command your DB will be available. restore database 'Database_Name' with recovery

Note: Step 2 will take some time to recover.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.