How to fix Error 4215 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 4215 – Log Not Truncated (Pending Replication/CDC)

Why This Error Happens

This error occurs because SQL Server’s transaction log cannot be truncated when there are log records that have not yet been consumed by the Log Reader Agent (for Transactional Replication) or the Capture Job (for Change Data Capture). This typically happens when the Log Reader Agent or CDC Capture job is stopped, disabled, or failing silently, causing a backlog of unprocessed transactions. Additionally, this can occur if replication or CDC was improperly removed from the database, leaving orphaned metadata that still signals pending log records to SQL Server.

Step-by-Step Resolution Guide

Step 1: Verify the Status of the Log Reader Agent or CDC Capture Job

  • Open SQL Server Management Studio (SSMS) and connect to the instance.
  • Navigate to Replication > Local Publications (if using Transactional Replication) and check if the Log Reader Agent job is running under SQL Server Agent > Jobs.
  • For CDC, run the following query to check job status:
  EXEC sys.sp_cdc_help_jobs;
  • If the job is stopped or disabled, right-click and select Start Job at Step… in SSMS.

Step 2: Check SQL Server Agent Service Status on Windows Server 2025 / Windows 11

  • Open Services.msc (Win + R, type services.msc).
  • Locate SQL Server Agent (MSSQLSERVER) or your named instance.
  • Ensure the Service Status is Running and the Startup Type is set to Automatic.
  • If stopped, right-click and select Start, then re-check the Log Reader Agent job status.

Step 3: Identify and Clear the Blocking Transaction Log Records

  • Run the following query to identify the oldest active transaction blocking log truncation:
  SELECT log_reuse_wait_desc FROM sys.databases WHERE name = 'YourDatabaseName';
  • If the result shows REPLICATION, verify replication is configured correctly; if CDC, check sys.dm_cdc_log_scan_sessions for scan errors.
  • Restart the Log Reader Agent job to attempt processing the backlog.

Step 4: Manually Mark Transactions as Distributed or Captured (If Replication/CDC is Decommissioned)

  • If replication or CDC is no longer in use but the error persists, run sp_repldone to manually clear the pending log markers:
  USE YourDatabaseName;
  EXEC sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 1;
  • Caution: Only run this command if you are certain replication/CDC data is no longer needed, as this permanently discards pending transaction markers.

Step 5: Force a Transaction Log Backup

  • Once the blocking job is running or sp_repldone has been executed, force a log backup to clear the virtual log files (VLFs):
  BACKUP LOG YourDatabaseName TO DISK = 'C:\Backups\YourDatabaseName_Log.trn';
  • Monitor the log file size via DBCC SQLPERF(LOGSPACE); to confirm truncation has occurred.

Alternative or Verification Steps

  • Verification: Run DBCC SQLPERF(LOGSPACE); to confirm the “Log Space Used (%)” has decreased, indicating successful truncation.
  • Alternative: If the Log Reader Agent continues to fail due to corruption, consider reinitializing the subscription or dropping and re-adding the CDC instance using sys.sp_cdc_disable_db and sys.sp_cdc_enable_db.