HADR_RECOVERY_WAIT_FOR_UNDO SQL Server Wait Type

Wait Type HADR_RECOVERY_WAIT_FOR_UNDO

The wait type HADR_RECOVERY_WAIT_FOR_UNDO is ranked #287 by Stedman Solutions and Database Health Monitor.

Wait statistics, in the context of SQL Server, refer to the amount of time that a query spends waiting to access data in the database. When a client application requests data from the database, the request is placed in a queue and the client application must wait for its turn to access the data. The time that the query spends waiting is called a "wait" and is tracked by SQL Server. This information can be used to identify potential performance bottlenecks and optimize the performance of the database. Wait statistics are commonly used by database administrators to diagnose and troubleshoot performance issues in SQL Server.


In SQL Server, wait types provide valuable insights into what processes are slowing down or causing delays. One wait type specific to Always On Availability Groups is HADR_RECOVERY_WAIT_FOR_UNDO. This wait type appears during failover or recovery operations when SQL Server is waiting for the undo phase to complete. In this post, we’ll explain what HADR_RECOVERY_WAIT_FOR_UNDO means, when it occurs, and how it can affect your SQL Server environment.

What Is the HADR_RECOVERY_WAIT_FOR_UNDO Wait Type?

The HADR_RECOVERY_WAIT_FOR_UNDO wait type occurs during the recovery process in Always On Availability Groups. When a secondary replica transitions into the primary role (such as during a failover), SQL Server ensures that all in-flight transactions are either completed or rolled back to maintain data consistency. The process of rolling back uncommitted transactions is known as the undo phase.

During this time, SQL Server must wait until all uncommitted transactions on the new primary replica are undone before it can fully bring the database online. This ensures that the database is in a consistent state before accepting new queries or updates.

When Does HADR_RECOVERY_WAIT_FOR_UNDO Appear?

This wait type typically appears during:

  • Failover Events – When an Availability Group fails over to a secondary replica, the new primary replica must finish rolling back uncommitted transactions before it becomes fully operational.
  • Manual Role Changes – During planned failovers or role switches, SQL Server must complete the undo phase as part of the recovery process.
  • Replica Recovery After Crash – When a secondary replica recovers from a crash or unexpected shutdown, it must complete undo operations for any incomplete transactions.

The length of this wait depends on the number of uncommitted transactions, their complexity, and the performance of the replica’s storage and CPU.

Why HADR_RECOVERY_WAIT_FOR_UNDO Waits Matter

While the HADR_RECOVERY_WAIT_FOR_UNDO wait type is a normal part of SQL Server’s recovery process, long waits can delay the failover process or the availability of the new primary replica. Prolonged undo waits may signal:

  • Large Number of Uncommitted Transactions – If there are many in-flight transactions at the time of failover, the undo phase may take longer to complete.
  • Slow Disk Performance – Undo operations rely on efficient I/O to process transaction rollbacks. If the disk subsystem is slow, it can increase wait times.
  • Heavy Transactional Workloads – Environments with frequent, large transactions are more likely to experience longer undo phases during recovery.

How to Address HADR_RECOVERY_WAIT_FOR_UNDO Waits

To minimize HADR_RECOVERY_WAIT_FOR_UNDO waits and improve failover performance, consider the following strategies:

  • Optimize Transactions – Keep transactions as short as possible to reduce the number of uncommitted transactions at any given time. Avoid long-running transactions that can extend the undo phase.
  • Improve Disk Performance – Use high-performance storage (such as SSDs) for transaction logs and data files to speed up undo operations.
  • Monitor Replica Workloads – Monitor and balance workloads across primary and secondary replicas to avoid overloading any one replica, which can lead to longer recovery times.
  • Test Failover Scenarios – Regularly test failover scenarios in a non-production environment to identify and resolve potential bottlenecks in the recovery process.

Conclusion

The HADR_RECOVERY_WAIT_FOR_UNDO wait type in SQL Server occurs when the system is waiting for uncommitted transactions to be rolled back during the recovery process in Always On Availability Groups. While these waits are a normal part of maintaining data consistency, long undo waits can delay failovers and impact availability. By optimizing transaction workloads, improving disk performance, and testing failover scenarios, you can minimize these waits and ensure smoother transitions in high availability environments.

For expert help with Always On Availability Groups, failover tuning, and SQL Server performance optimization, Stedman Solutions offers managed services to keep your SQL Server environment running efficiently and reliably.


Watch on YouTube


Find out more about our SQL Server Managed Services

Applies to

    Related Waits

    HADR_AG_MUTEX
    HADR_AR_CRITICAL_SECTION_ENTRY
    HADR_AR_MANAGER_MUTEX
    HADR_AR_UNLOAD_COMPLETED
    HADR_ARCONTROLLER_NOTIFICATIONS_SUBSCRIBER_LIST
    HADR_BACKUP_BULK_LOCK
    HADR_BACKUP_QUEUE
    HADR_CLUSAPI_CALL
    HADR_COMPRESSED_CACHE_SYNC
    HADR_CONNECTIVITY_INFO
    HADR_DATABASE_FLOW_CONTROL
    HADR_DATABASE_VERSIONING_STATE
    HADR_DATABASE_WAIT_FOR_RESTART
    HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING
    HADR_DB_COMMAND
    HADR_DB_OP_COMPLETION_SYNC
    HADR_DB_OP_START_SYNC
    HADR_DBR_SUBSCRIBER
    HADR_DBR_SUBSCRIBER_FILTER_LIST
    HADR_DBSEEDING
    HADR_DBSEEDING_LIST
    HADR_DBSTATECHANGE_SYNC
    HADR_FABRIC_CALLBACK
    HADR_FILESTREAM_BLOCK_FLUSH
    HADR_FILESTREAM_FILE_CLOSE
    HADR_FILESTREAM_FILE_REQUEST
    HADR_FILESTREAM_IOMGR
    HADR_FILESTREAM_MANAGER
    HADR_GROUP_COMMIT
    HADR_LOGCAPTURE_SYNC
    HADR_LOGCAPTURE_WAIT
    HADR_LOGPROGRESS_SYNC
    HADR_NOTIFICATION_DEQUEUE
    HADR_NOTIFICATION_WORKER_EXCLUSIVE_ACCESS
    HADR_NOTIFICATION_WORKER_STARTUP_SYNC
    HADR_NOTIFICATION_WORKER_TERMINATION_SYNC
    HADR_PARTNER_SYNC
    HADR_READ_ALL_NETWORKS
    HADR_RECOVERY_WAIT_FOR_CONNECTION
    HADR_REPLICAINFO_SYNC
    HADR_SYNC_COMMIT
    HADR_SYNCHRONIZING_THROTTLE
    HADR_TDS_LISTENER_SYNC
    HADR_TDS_LISTENER_SYNC_PROCESSING
    HADR_TIMER_TASK
    HADR_TRANSPORT_DBRLIST
    HADR_TRANSPORT_FLOW_CONTROL
    HADR_TRANSPORT_SESSION
    HADR_WORK_POOL
    HADR_WORK_QUEUE
    HADR_XRF_STACK_ACCESS

    See Also


    All Wait Types
    HADR_RECOVERY_WAIT_FOR_UNDO SQL Server Wait Type