mediumTransaction Log

LOGMGR_RESERVE_APPEND Wait Type Explained

Fix SQL Server LOGMGR_RESERVE_APPEND waits caused by transaction log space pressure. Diagnostic queries, fix scripts, and prevention strategies for DBAs.

Quick Answer

LOGMGR_RESERVE_APPEND occurs when SQL Server cannot reserve log space for new transaction log records due to insufficient transaction log capacity or slow log truncation. This indicates the transaction log is experiencing capacity pressure, typically from delayed log backups, long-running transactions, or undersized log files.

Root Cause Analysis

The SQL Server Log Manager uses a reservation system to ensure transaction atomicity by pre-allocating log space before writing records. When a session needs to write log records, it first calls the Log Manager to reserve the required space. LOGMGR_RESERVE_APPEND waits occur when this reservation request cannot be satisfied immediately.

The Log Manager maintains internal structures tracking available log space, active Virtual Log Files (VLFs), and pending log records. When log space becomes constrained, the Log Manager queues reservation requests in a wait state. This happens when the active portion of the log approaches the physical log file boundaries or when log truncation cannot reclaim space fast enough.

Common scenarios triggering this wait include databases in FULL recovery mode without regular log backups, causing the log to grow until it hits size limits. Long-running transactions prevent log truncation by holding the oldest active LSN, creating a bottleneck. Excessive VLF fragmentation from poor log file growth patterns also contributes by making space allocation inefficient.

In SQL Server 2016 and later, the Log Manager improved its space reservation algorithms, but the fundamental behavior remains unchanged. SQL Server 2019 introduced better telemetry for log space pressure through extended events. SQL Server 2022 enhanced log backup performance with optimizations that can reduce the frequency of these waits in high-throughput scenarios.

AutoDBA checks Transaction log sizing, backup frequency monitoring, and VLF fragmentation analysis across your entire SQL Server instance in 60 seconds. Download the free diagnostic script and see what else needs attention.

Diagnostic Queries

-- Check current log space usage and VLF counts
SELECT 
    db.name AS database_name,
    ls.cntr_value AS log_size_kb,
    lu.cntr_value AS log_used_kb,
    CAST(CAST(lu.cntr_value AS FLOAT) / CAST(ls.cntr_value AS FLOAT) * 100 AS DECIMAL(5,2)) AS log_used_percent,
    df.physical_name,
    (SELECT COUNT(*) FROM sys.dm_db_log_info(db.database_id)) AS vlf_count
FROM sys.databases db
INNER JOIN sys.dm_os_performance_counters ls ON db.name = ls.instance_name AND ls.counter_name = 'Log File(s) Size (KB)'
INNER JOIN sys.dm_os_performance_counters lu ON db.name = lu.instance_name AND lu.counter_name = 'Log File(s) Used Size (KB)'
INNER JOIN sys.database_files df ON df.type = 1
WHERE db.database_id > 4
ORDER BY log_used_percent DESC;
-- Identify long-running transactions blocking log truncation
SELECT 
    s.session_id,
    s.login_name,
    s.host_name,
    s.program_name,
    t.transaction_begin_time,
    DATEDIFF(MINUTE, t.transaction_begin_time, GETDATE()) AS duration_minutes,
    t.transaction_type,
    t.transaction_state,
    r.blocking_session_id,
    r.wait_type,
    r.wait_time,
    SUBSTRING(qt.text, (r.statement_start_offset/2)+1,
        ((CASE r.statement_end_offset
            WHEN -1 THEN DATALENGTH(qt.text)
            ELSE r.statement_end_offset
        END - r.statement_start_offset)/2)+1) AS statement_text
FROM sys.dm_tran_active_transactions t
INNER JOIN sys.dm_tran_session_transactions st ON t.transaction_id = st.transaction_id
INNER JOIN sys.dm_exec_sessions s ON st.session_id = s.session_id
LEFT JOIN sys.dm_exec_requests r ON s.session_id = r.session_id
OUTER APPLY sys.dm_exec_sql_text(r.sql_handle) qt
WHERE t.transaction_begin_time < DATEADD(MINUTE, -5, GETDATE())
ORDER BY t.transaction_begin_time;
-- Check log backup history and frequency
SELECT TOP 10
    database_name,
    backup_start_date,
    backup_finish_date,
    DATEDIFF(SECOND, backup_start_date, backup_finish_date) AS backup_duration_seconds,
    backup_size / 1024 / 1024 AS backup_size_mb,
    compressed_backup_size / 1024 / 1024 AS compressed_size_mb
FROM msdb.dbo.backupset
WHERE type = 'L' -- Log backups only
ORDER BY backup_start_date DESC;
-- Monitor current LOGMGR_RESERVE_APPEND waits
SELECT 
    session_id,
    wait_type,
    wait_time,
    blocking_session_id,
    resource_description,
    SUBSTRING(qt.text, (r.statement_start_offset/2)+1,
        ((CASE r.statement_end_offset
            WHEN -1 THEN DATALENGTH(qt.text)
            ELSE r.statement_end_offset
        END - r.statement_start_offset)/2)+1) AS current_statement
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) qt
WHERE wait_type = 'LOGMGR_RESERVE_APPEND'
ORDER BY wait_time DESC;
-- Analyze VLF fragmentation for log files
SELECT 
    db_name(vlf.database_id) AS database_name,
    vlf.file_id,
    COUNT(*) AS vlf_count,
    SUM(CASE WHEN vlf.vlf_status = 2 THEN 1 ELSE 0 END) AS active_vlfs,
    MIN(vlf.vlf_size_mb) AS min_vlf_size_mb,
    MAX(vlf.vlf_size_mb) AS max_vlf_size_mb,
    AVG(vlf.vlf_size_mb) AS avg_vlf_size_mb
FROM sys.dm_db_log_info(NULL) vlf
WHERE vlf.database_id > 4
GROUP BY vlf.database_id, vlf.file_id
HAVING COUNT(*) > 100  -- Flag databases with excessive VLFs
ORDER BY vlf_count DESC;

Fix Scripts

Immediate log space relief through log backup Performs a transaction log backup to immediately free up log space for truncation.

-- Replace 'YourDatabase' with actual database name
-- Ensure backup location exists and SQL Server has write permissions
BACKUP LOG [YourDatabase] 
TO DISK = 'C:\Backups\YourDatabase_LogBackup_' + REPLACE(CONVERT(varchar(19), GETDATE(), 120), ':', '-') + '.trn'
WITH COMPRESSION, CHECKSUM;

-- Verify log space was reclaimed
SELECT 
    name,
    log_reuse_wait_desc,
    (size * 8) / 1024 AS log_size_mb,
    (FILEPROPERTY(name, 'SpaceUsed') * 8) / 1024 AS log_used_mb
FROM sys.database_files 
WHERE type = 1;

Caveat: Only works for databases in FULL or BULK_LOGGED recovery mode. Test backup location accessibility first.

Expand transaction log file size Increases log file capacity to reduce immediate space pressure.

-- Check current log file configuration first
SELECT 
    name AS logical_name,
    physical_name,
    (size * 8) / 1024 AS current_size_mb,
    (max_size * 8) / 1024 AS max_size_mb,
    growth,
    is_percent_growth
FROM sys.database_files 
WHERE type = 1;

-- Expand log file - adjust size based on workload requirements
ALTER DATABASE [YourDatabase]
MODIFY FILE (
    NAME = 'YourDatabase_Log',  -- Replace with actual logical name
    SIZE = 2048MB,              -- Set appropriate size
    MAXSIZE = 10240MB,          -- Set reasonable maximum
    FILEGROWTH = 512MB          -- Use fixed MB growth, not percentage
);

Caveat: Monitor disk space availability. Large log file expansions can impact performance during the operation.

Fix excessive VLF fragmentation Rebuilds transaction log with optimal VLF structure when VLF count exceeds recommended thresholds.

-- WARNING: This operation requires database downtime and full backup
-- Step 1: Backup the database first
BACKUP DATABASE [YourDatabase] 
TO DISK = 'C:\Backups\YourDatabase_BeforeLogRebuild.bak'
WITH COMPRESSION, CHECKSUM;

-- Step 2: Backup transaction log
BACKUP LOG [YourDatabase] 
TO DISK = 'C:\Backups\YourDatabase_FinalLogBackup.trn';

-- Step 3: Shrink log file to minimum size
DBCC SHRINKFILE('[YourDatabase_Log]', 1);

-- Step 4: Resize log file with optimal initial size
ALTER DATABASE [YourDatabase]
MODIFY FILE (
    NAME = 'YourDatabase_Log',
    SIZE = 1024MB,           -- Adjust based on typical log usage
    FILEGROWTH = 512MB       -- Fixed growth increments
);

Caveat: Requires maintenance window. Shrinking log files can cause temporary performance degradation. Test in development first.

AutoDBA generates fix scripts like these automatically, with impact estimates and rollback SQL included.

Prevention

Implement automated transaction log backups with frequency matching your RTO requirements, typically every 15-30 minutes for production systems. Configure log files with appropriate initial sizing based on peak transaction volume, avoiding small initial sizes that trigger frequent auto-growth events.

Set transaction log growth to fixed MB increments rather than percentage growth to maintain consistent VLF sizes. Size initial log files to handle 2-4 hours of peak transaction activity without growth. Monitor log space usage with alerts at 70% and 85% thresholds.

Establish monitoring for long-running transactions using SQL Agent jobs that check sys.dm_tran_active_transactions for transactions exceeding defined time limits. Configure database mail alerts when VLF counts exceed 100 per database.

For databases with predictable high transaction volumes, consider multiple log files on separate storage subsystems to improve write throughput. Implement regular log space trending analysis to proactively adjust log file sizing before capacity issues occur.

Use extended events sessions to capture and analyze log-related wait events in development environments to validate log sizing decisions before production deployment. Review backup compression settings and backup destination performance, as slow log backups directly contribute to log space pressure.

Need hands-on help?

Dealing with persistent logmgr_reserve_append issues across your environment? Samix Technology provides hands-on SQL Server performance consulting with 15+ years of production DBA experience.

Related Pages