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

Troubleshooting Guide: Error 5265 – USED Pages Mismatch in SQL Server 2025

Why This Error Happens

Error 5265 occurs when DBCC CHECKALLOC detects a discrepancy between the number of used pages recorded in the system metadata (sys.allocation_units or sys.sysindexes) and the actual number of pages physically allocated within the data file. This mismatch is typically caused by database corruption resulting from an unexpected shutdown, storage subsystem failures (disk, SAN, or controller errors), or a bug triggered during a page allocation/deallocation sequence that was interrupted mid-transaction. In rare cases, running SQL Server 2025 on Windows Server 2025 with outdated storage drivers or filesystem-level corruption (NTFS/ReFS) can also trigger a false positive during the allocation scan.

Step-by-Step Resolution Guide

Step 1: Isolate the Database and Verify Corruption Scope

  • Place the affected database in single-user mode or take it offline for write operations to prevent further corruption:
  ALTER DATABASE [YourDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  • Run a full consistency check to capture the complete scope of the error before attempting repairs:
  DBCC CHECKDB ('YourDB') WITH NO_INFOMSGS, ALL_ERRORMSGS;
  • Note the specific Page IDs and Object IDs referenced in the 5265 output for cross-verification later.

Step 2: Check Underlying Hardware and Storage Drivers

  • Navigate to Device Manager on Windows Server 2025 and verify Storage Controllers for pending driver updates.
  • Check the Windows Event Viewer (Windows Logs > System) for Event ID 153 or 157, which indicate I/O retries or disk timeout issues that often correlate with SQL allocation errors.
  • If using Storage Spaces Direct or a SAN, run Get-PhysicalDisk in PowerShell to ensure the HealthStatus is reported as “Healthy.”

Step 3: Attempt Repair Using DBCC CHECKALLOC

  • If the corruption is isolated to allocation pages only (and not user data), run the specific allocation repair command:
  DBCC CHECKALLOC ('YourDB', REPAIR_ALLOW_DATA_LOSS);
  • Caution: This command may result in data loss for the specific pages that are incorrectly allocated; ensure a backup exists prior to execution.
  • Monitor the output grid for a return code of 0, confirming the repair executed without further systemic errors.

Step 4: Restore From a Clean Backup (If Repair Fails)

  • If REPAIR_ALLOW_DATA_LOSS does not resolve the discrepancy, the fastest path to a stable state is restoring the last known good full backup.
  • Use SQL Server Management Studio (SSMS) or T-SQL to restore the .bak file to a new database name to verify integrity before overwriting production:
  RESTORE DATABASE [YourDB_Test] FROM DISK = 'C:\Backups\YourDB.bak' WITH NORECOVERY;
  • Apply any available transaction log backups to minimize data loss up to the point of failure.

Alternative or Verification Steps

  • Verification: After repair or restoration, re-run DBCC CHECKDB ('YourDB') WITH NO_INFOMSGS to confirm the output returns “0 allocation errors and 0 consistency errors.”
  • Alternative: If corruption persists across multiple nightly checks, migrate the database files to a different physical volume (via ALTER DATABASE MODIFY FILE) to rule out a specific faulty sector on the current disk array.