Quick Answer
DBMIRRORING_CMD occurs when database mirroring sessions wait for log records to flush to disk before transmission to the mirror server. This wait is expected during normal mirroring operations and indicates the principal database is ensuring transaction durability before sending log data to the mirror.
Root Cause Analysis
DBMIRRORING_CMD waits occur within the database mirroring subsystem when the log capture thread on the principal server must wait for the log manager to flush uncommitted log records to disk. The mirroring engine cannot transmit log blocks to the mirror server until those blocks are hardened to storage, ensuring crash consistency.
The wait specifically manifests in the mirroring worker threads that read from the transaction log. These threads use the log scan process to identify log records eligible for transmission, but they must coordinate with the log writer and checkpoint processes to ensure log blocks are physically written before network transmission begins.
In SQL Server 2016 and later versions, the mirroring subsystem leverages improved log flush algorithms that reduce the frequency of these waits during steady-state operations. However, workloads with large transactions or burst write patterns still generate significant DBMIRRORING_CMD waits because the mirroring threads must pause until the entire transaction's log footprint reaches disk.
The wait duration correlates directly with storage subsystem performance. Slow log drive responses amplify DBMIRRORING_CMD waits, creating a cascading effect where mirroring lag increases exponentially. This differs from WRITELOG waits, which affect user transactions directly, because DBMIRRORING_CMD only impacts the replication stream timing.
High-frequency small transactions generate less DBMIRRORING_CMD wait time than equivalent throughput from large transactions because log flush operations batch smaller writes more efficiently. The log writer consolidates multiple small transaction commits into single I/O operations, reducing the per-transaction wait overhead for mirroring threads.
AutoDBA checks Database mirroring configuration, transaction log sizing, and storage performance metrics across your entire SQL Server instance in 60 seconds. Download the free diagnostic script and see what else needs attention.
Diagnostic Queries
-- Current mirroring wait statistics and session state
SELECT
db.name AS database_name,
dm.mirroring_role_desc,
dm.mirroring_state_desc,
dm.mirroring_safety_level_desc,
ws.wait_time_ms,
ws.waiting_tasks_count,
ws.signal_wait_time_ms
FROM sys.databases db
INNER JOIN sys.database_mirroring dm ON db.database_id = dm.database_id
CROSS JOIN sys.dm_os_wait_stats ws
WHERE ws.wait_type = 'DBMIRRORING_CMD'
AND dm.mirroring_state IS NOT NULL;
-- Active mirroring sessions with current send queue and redo queue performance counters
SELECT
instance_name AS database_name,
counter_name,
cntr_value
FROM sys.dm_os_performance_counters
WHERE object_name LIKE '%Database Mirroring%'
AND counter_name IN ('Log Send Queue KB', 'Redo Queue KB', 'Log Bytes Sent/sec', 'Redo Bytes/sec', 'Transaction Delay')
ORDER BY instance_name, counter_name;
-- Transaction log file stats showing flush patterns affecting mirroring
SELECT
db_name(database_id) AS database_name,
log_reuse_wait_desc,
cntr_value AS log_flush_waits,
cntr_type
FROM sys.dm_os_performance_counters
WHERE counter_name IN ('Log Flush Waits/sec', 'Log Flush Wait Time')
AND instance_name IN (SELECT name FROM sys.databases WHERE database_id > 4);
-- Recent blocking and wait information for mirroring worker threads
SELECT TOP 20
r.session_id,
r.wait_type,
r.wait_time,
r.last_wait_type,
r.wait_resource,
t.text AS current_statement,
r.blocking_session_id
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) t
WHERE r.wait_type = 'DBMIRRORING_CMD'
OR r.last_wait_type = 'DBMIRRORING_CMD'
ORDER BY r.wait_time DESC;
-- Historical wait patterns for mirroring command waits
SELECT
wait_type,
waiting_tasks_count,
wait_time_ms,
max_wait_time_ms,
signal_wait_time_ms,
wait_time_ms / NULLIF(waiting_tasks_count, 0) AS avg_wait_ms
FROM sys.dm_os_wait_stats
WHERE wait_type = 'DBMIRRORING_CMD';
Fix Scripts
Optimize Transaction Log File Configuration
-- Resize transaction log to reduce autogrowth events during peak mirroring
-- TEST IN DEVELOPMENT FIRST - requires maintenance window for large operations
USE master;
GO
DECLARE @database_name NVARCHAR(128) = 'YourMirroredDatabase';
DECLARE @log_size_mb INT = 8192; -- Adjust based on workload analysis
DECLARE @sql NVARCHAR(MAX) =
'ALTER DATABASE ' + QUOTENAME(@database_name) +
' MODIFY FILE (NAME = ''' + @database_name + '_Log'', SIZE = ' +
CAST(@log_size_mb AS VARCHAR(10)) + 'MB, FILEGROWTH = 512MB);';
PRINT @sql;
-- EXEC sp_executesql @sql; -- Uncomment after verification
Enable Instant File Initialization for Log Performance
-- Verify instant file initialization status for the SQL Server service account
-- This affects log file growth operations that can cause mirroring delays
SELECT
servicename,
service_account,
instant_file_initialization_enabled
FROM sys.dm_server_services
WHERE servicename LIKE '%SQL Server%';
-- If IFI is disabled, enable through Windows security policy or startup trace flag
-- DBCC TRACEON(1117, 1118, -1); -- Legacy trace flags for older versions
Monitor and Adjust Mirroring Partner Connection Timeout
-- Increase partner timeout to prevent unnecessary failovers during high DBMIRRORING_CMD waits
-- Default is 10 seconds, consider 20-30 seconds for storage-constrained environments
USE YourMirroredDatabase;
GO
-- WARNING: This affects failover timing, coordinate with stakeholders
ALTER DATABASE YourMirroredDatabase
SET PARTNER TIMEOUT 20; -- Seconds
Implement Log Flush Frequency Monitoring
-- Create monitoring job to track log flush performance affecting mirroring
-- Deploy as SQL Agent job running every 5 minutes during business hours
DECLARE @log_flush_waits BIGINT;
DECLARE @previous_waits BIGINT = 0; -- Store in persistent table in production
SELECT @log_flush_waits = cntr_value
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Log Flush Waits/sec'
AND instance_name = 'YourMirroredDatabase';
IF (@log_flush_waits - @previous_waits) > 100 -- Threshold per 5-minute interval
BEGIN
RAISERROR('High log flush waits detected: %d waits in 5 minutes', 16, 1, (@log_flush_waits - @previous_waits));
END;
AutoDBA generates fix scripts like these automatically, with impact estimates and rollback SQL included.
Prevention
Configure transaction log files with appropriate initial sizes based on peak transaction volume to eliminate autogrowth events during high-throughput periods. Size log files to accommodate 2-4 hours of peak transaction activity without requiring expansion.
Place transaction log files on dedicated storage with consistent low latency, preferably NVMe SSDs with write caching disabled or battery-backed write caches. Avoid shared storage configurations where mirrored databases compete with other I/O intensive applications for disk bandwidth.
Implement application-level transaction batching to reduce the frequency of large single transactions that force extended log flush operations. Design ETL processes and bulk operations to commit work in smaller, consistent batch sizes rather than single massive transactions.
Configure database mirroring with asynchronous mode (high-performance) instead of synchronous mode (high-safety) when application requirements permit slight data loss exposure. Synchronous mirroring amplifies DBMIRRORING_CMD waits because the principal must wait for both local log flush and mirror server acknowledgment.
Monitor log send queue sizes and establish alerting thresholds at 1GB queue depth to identify storage performance degradation before it impacts application performance. Implement automated log file space monitoring to prevent log file growth events during production hours.
Deploy SQL Server 2019 or later versions to leverage improved log flush algorithms and reduced lock contention in the log management subsystem. These versions show measurably reduced DBMIRRORING_CMD wait times compared to SQL Server 2016 and earlier releases.
Need hands-on help?
Dealing with persistent dbmirroring_cmd issues across your environment? Samix Technology provides hands-on SQL Server performance consulting with 15+ years of production DBA experience.