SQL

Fix SQL Server Database Stuck in Recovery in 5 Ways

12 min read

SQL Server shows the In Recovery state while it replays and rolls back the transaction log after a restart. Recovery ends by itself when the three phases finish and the database comes online.

Five ways below tell you when to wait, how to find the slowdown, how to shorten the next recovery and how to restore the data when recovery fails. Every way names its data risk.

Quick SummaryFix a SQL Server database in recovery in five ways. Check the error log for the phase and the percentage first. Track progress with the DB STARTUP row in sys.dm_exec_requests. Find the slowdown in open transactions or in a log with too many virtual log files. Enable accelerated database recovery on SQL Server 2019 or later to shorten the next recovery. Restore the backup chain when recovery fails. Use SQL Recovery when no backup restores.

What Does the In Recovery State Mean in SQL Server?

Microsoft states that SQL Server executes recovery on every database when the instance starts. Recovery starts from the last checkpoint and brings the database to a transactionally consistent state. The sys.databases view shows the state as RECOVERING.

Microsoft calls RECOVERING a transient state. The database comes online when recovery succeeds and becomes SUSPECT when recovery fails. Nobody can query the database while it recovers.

Phase What SQL Server does Error log text
Analysis Finds the last checkpoint and builds the dirty page table and the active transaction table Phase 1 of 3
Redo Rolls forward the logged modifications that did not reach the data files, starting at the minimum LSN in the dirty page table Phase 2 of 3
Undo Rolls back the transactions that were open when the database stopped. The database comes online after the rollback Phase 3 of 3

Microsoft states that the error log records the progress of every stage. A normal line looks like the sample below.

Recovery of database 'SalesDB' (7) is 43% complete (approximately 192 seconds remain). Phase 2 of 3. This is an informational message only. No user action is required.

Do You Know?Microsoft states that a failover or another non clean shutdown makes recovery necessary. Committed modifications can be missing from the data files and uncommitted modifications can be present. Recovery fixes both cases.

Why Does Recovery Take So Long?

Three causes appear in Microsoft documentation. The cause decides the way you choose below.

Cause What Microsoft states Fix
A long uncommitted transaction at shutdown The recovery after the restart can take much longer than the time that the recovery interval option sets Method 2 and Method 3
Too many virtual log files Several hundred thousand VLFs cause long recovery at startup and slow restore and attach operations Method 2
A damaged data or log file The database becomes SUSPECT when recovery fails Method 4 and Method 5

Which Way Fixes Your Case?

Your situation Your way Data risk
The error log shows a rising percentage Method 1 None. The database comes online when the phases finish
The percentage rises slowly after a crash with a large transaction still open Method 1 and then Method 3 None
Every restart takes long and the log has many virtual log files Method 2 None. Take a valid backup before you resize the log
Long recoveries repeat and the instance is SQL Server 2019 or later Method 3 Small overhead on workloads with heavy data modification
The error log shows an error and the state becomes SUSPECT Method 4 Work after the last log backup is lost unless a tail log backup works
No backup restores Method 5 None on the original files because SQL Recovery works on a copy

How Do You Fix a Database Stuck in Recovery?

Method 1: Track the Progress and Wait for the Phases to Finish

Open the error log first. Search it for the recovery messages of your database.

EXEC sys.sp_readerrorlog 0, 1, N'Recovery of database', N'SalesDB';

EXEC sys.sp_readerrorlog 0, 1, N'Recovery completed', N'SalesDB';

Every line shows the percentage, the estimated seconds and the phase. The last line shows the time that the analysis, redo and undo phases used.

The same progress is available without the log. Microsoft shows the DB STARTUP command in sys.dm_exec_requests and states that percent_complete matches the error log value for the current stage.

SELECT session_id, command, percent_complete,
       total_elapsed_time / 60000.0 AS elapsed_minutes,
       estimated_completion_time / 60000.0 AS remaining_minutes
FROM sys.dm_exec_requests
WHERE command = N'DB STARTUP';

SELECT name, state_desc
FROM sys.databases
WHERE name = N'SalesDB';

A rising percentage or a phase that moves from 1 to 2 to 3 means that recovery works. The state shows ONLINE after the undo phase.

Microsoft gives no standard duration for recovery. A large log needs more time than a small one.

Heads UpA restart of the instance in the middle of recovery starts the recovery of every database again. Wait while the percentage moves.

Method 2: Find What Slows the Recovery

Count the virtual log files of the database. Microsoft states that too many small VLFs slow database startup and log backup and restore operations.

SELECT COUNT(*) AS vlf_count
FROM sys.dm_db_log_info(DB_ID(N'SalesDB'));

Microsoft lists a long recovery at startup among the symptoms when the count reaches several hundred thousand. Microsoft advises a maximum of several thousand.

Fix a high count after the database is online. Take a valid backup first. Shrink the log file and grow it back to the size that you need in one step.

USE SalesDB;
DBCC SHRINKFILE (N'SalesDB_log', 1);

ALTER DATABASE SalesDB
MODIFY FILE (NAME = N'SalesDB_log', SIZE = 8GB);

Check the open transactions next. Microsoft states that an application that starts a transaction and never commits it stops the log from truncating. The undo phase must roll back that work after a crash.

DBCC OPENTRAN (SalesDB);

SELECT s.session_id, s.login_name, at.transaction_begin_time,
       DATEDIFF(MINUTE, at.transaction_begin_time, GETDATE()) AS open_minutes
FROM sys.dm_tran_active_transactions AS at
JOIN sys.dm_tran_session_transactions AS st
  ON st.transaction_id = at.transaction_id
JOIN sys.dm_exec_sessions AS s
  ON s.session_id = st.session_id
ORDER BY at.transaction_begin_time;

Commit or roll back the oldest transaction in the application. A short transaction shortens the next recovery.

Method 3: Enable Accelerated Database Recovery

Accelerated database recovery (ADR) is available from SQL Server 2019. Microsoft states that traditional recovery time is roughly proportional to the size of the longest active transaction. With ADR the recovery time is not affected by long transactions and is typically instantaneous.

SELECT name, is_accelerated_database_recovery_on
FROM sys.databases
WHERE name = N'SalesDB';

ALTER DATABASE SalesDB
SET ACCELERATED_DATABASE_RECOVERY = ON;
Item What Microsoft states
Versions SQL Server 2019 and later. ADR is always on in Azure SQL Database and Azure SQL Managed Instance
Database mirroring ADR is not supported in databases that use database mirroring
Overhead The overhead ranges from not detectable to minor for most workloads. Workloads with heavy data modification can see more page splits and more log
Persistent version store DML statements can fail when the database has no room for the persistent version store
Replication and CDC Transactional replication, snapshot replication and change data capture disable the aggressive log truncation of ADR

Heads UpEnable ADR after the database is online. The setting shortens later recoveries. Plan space for the persistent version store before you enable it.

Method 4: Restore the Backup Chain When Recovery Fails

Recovery fails when the error log shows an error and not an informational message. Microsoft states that the database then becomes SUSPECT. Try a tail log backup first.

BACKUP LOG SalesDB
TO DISK = N'D:\Backup\SalesDB_tail.trn'
WITH NO_TRUNCATE;

RESTORE DATABASE SalesDB
FROM DISK = N'D:\Backup\SalesDB_full.bak'
WITH NORECOVERY, REPLACE;

RESTORE LOG SalesDB
FROM DISK = N'D:\Backup\SalesDB_log1.trn'
WITH NORECOVERY;

RESTORE DATABASE SalesDB WITH RECOVERY;

DBCC CHECKDB (SalesDB) WITH ALL_ERRORMSGS, NO_INFOMSGS;

Apply every log backup before the last statement. Microsoft states that no more log backups apply after the undo phase and the database goes online. The post on restoring a database with NORECOVERY explains the option and error 3117 explains the failure when a step uses RECOVERY too early.

Use the emergency mode steps in the post on recovering a SQL database from suspect mode when no backup restores. Error 3456 is a common reason for a SUSPECT state after a redo failure.

Method 5: Recover the Data With SQL Recovery

Choose SQL Recovery when no backup restores and the emergency repair fails or loses data that you need. SQL Recovery scans a copy of the damaged MDF and NDF files and your original files remain untouched.

SQL Recovery previews tables, views, triggers, rules, functions and stored procedures. SQL Recovery then exports them to a SQL Server database, to SQL scripts or to CSV files.

Download SQL Recovery Buy SQL Recovery

  1. Install SQL Recovery and select Add File.

Add file option in SQL Recovery

  1. Browse to the MDF file and select Advanced Scan. Confirm the SQL Server version and tick the deleted records option.

Advanced Scan and SQL Server version options in SQL Recovery

  1. Open the preview and check the recovered database components.

Preview of recovered SQL database objects in SQL Recovery

  1. Select Export and save the objects to a SQL Server database, to SQL scripts or to CSV files.

Export options in SQL Recovery

How Is In Recovery Different From Recovery Pending and Restoring?

Four states look alike in Object Explorer. Microsoft defines every one on its database states page.

State What Microsoft states What to do
RECOVERING The database is being recovered. The state is transient and ends online or SUSPECT Method 1
RECOVERY PENDING A resource related error stopped recovery. Files can be missing and the user must act Follow the post on recovery pending in SQL Server
SUSPECT At least the primary filegroup is suspect and the database cannot be recovered at startup Method 4 or Method 5
RESTORING One or more files of the primary filegroup are being restored Follow the post on a database stuck in restoring state

Which Specifications Does SQL Recovery Need?

Compare both tables with your system before you install SQL Recovery on the server or on another workstation.

Software Specifications

Attribute Detail
Software name SQL Recovery
Version 14.0
File types MDF and NDF
SQL Server versions 2025, 2022, 2019, 2017, 2016, 2014, 2012, 2008 R2, 2008, 2005 and 2000
Scan modes Quick Scan and Advanced Scan
Export options SQL Server database, SQL scripts and CSV
SQL Server installation Needed only for export to a live server
Demo limit Preview of every item and export of 25 records per table and 5 other objects

System Specifications

Component Requirement
Processor Intel Core 2 Duo E4600 at 2.40 GHz or equivalent
RAM 4 GB
Hard disk space 100 MB free
Operating system Windows 7, 8 and 10 (32 or 64 bit), Windows 11 (64 bit), Windows Server 2008, 2012 R2, 2016, 2019, 2022 and 2025
Framework Microsoft .NET Framework 4.5 or later
Permission Launch SQL Recovery as administrator

Common Questions on a Database in Recovery

How Long Does a SQL Server Database Remain in Recovery?

Microsoft gives no standard time. The time depends on the size of the longest active transaction at the crash and on the number of virtual log files. Track the percentage in the error log to see the estimate.

Should You Restart SQL Server While a Database Is in Recovery?

No. A restart starts the recovery of every database again. Wait while the percentage in the error log moves and restore from backup only when the log shows an error.

Is In Recovery the Same as Recovery Pending?

No. Microsoft defines RECOVERING as a transient state that ends online or SUSPECT. RECOVERY PENDING means that a resource related error stopped recovery and the user must act.

Can Accelerated Database Recovery Prevent Long Recovery?

It shortens the recovery. Microsoft states that with ADR the recovery time is not affected by long transactions and is typically instantaneous. ADR needs SQL Server 2019 or later and you enable it after the database is online.

Can You Query a Database While It Recovers?

No. Microsoft states that the database is unavailable in the RECOVERING state. Enterprise Edition can bring the database online after the redo phase while the undo phase still finishes. That needs a service restart.

Does Recovery Lose Data?

No. Recovery rolls forward committed modifications and rolls back uncommitted modifications. A failed recovery that ends SUSPECT needs a backup or a repair and the repair can lose data.

Who, How and WhyAndrew Jackson, Technical Content Specialist, is the author of this guide. The recovery phases, the Enterprise Edition note and the ADR syntax follow the Microsoft page on restore and recovery. The state definitions follow the Microsoft page on database states. The VLF and open transaction facts follow the Microsoft transaction log architecture guide. The ADR limits follow the Microsoft page on accelerated database recovery. The DB STARTUP query follows the Microsoft blog on tracking recovery progress, which is archived for SQL Server 2008. The error log syntax follows the Microsoft page for sp_readerrorlog. Verify every step on your version. The T-SQL was checked for syntax against Microsoft documentation and was not executed on a live server. The guide exists because a database in recovery looks stuck and a restart makes the wait longer.

Key Takeaways

  • The In Recovery state is transient. The database comes online when the analysis, redo and undo phases finish and becomes SUSPECT when recovery fails.
  • The error log and the DB STARTUP row in sys.dm_exec_requests show the phase and the percentage. A rising value means that recovery works.
  • A restart of the instance starts the recovery of every database again.
  • Long open transactions and a high count of virtual log files make recovery long.
  • Accelerated database recovery shortens later recoveries on SQL Server 2019 or later.
  • Restore the backup chain when recovery fails and use SQL Recovery when no backup restores.