Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1523: Sort Failure Fix Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1523 ("sort failure: the incorrect extent could not be...") is a corruption or resource problem, not a query syntax error. The fastest working set is: run DBCC CHECKDB on the affected database, check SQL Server error logs and Windows Event Viewer for disk or I/O errors, verify free disk space and memory, and if CHECKDB reports corruption, restore from a known-good backup or run a repair with REPAIR_ALLOW_DATA_LOSS only as a last resort. The error usually appears when a sort operation (ORDER BY, GROUP BY, DISTINCT, index build, or merge join) cannot allocate or read the extents it needs, often because of a damaged allocation structure or an exhausted tempdb. This guide walks through diagnosis and repair in the order that avoids making things worse.

What You'll Need

  • Membership in the sysadmin fixed server role or equivalent permissions to run DBCC CHECKDB and restore databases.
  • SQL Server Management Studio (SSMS) or Azure Data Studio connected to the instance.
  • Access to the SQL Server error log and Windows Event Viewer (or the Linux system logs if you run SQL Server on Linux).
  • A recent, verified backup of the affected database before you attempt any repair.
  • Enough free disk space on the data, log, and tempdb drives (at least the size of the largest database file plus room for the repair).

Step-by-Step

  1. Capture the exact error and context. Note the full message text, the database name, the query or job that triggered it, and the time. Error 1523 often appears alongside 823, 824, 825, or 605 errors, which point to I/O or allocation problems. The surrounding messages matter more than 1523 alone.
  2. Check free space and tempdb. In SSMS, right-click the instance, choose Reports > Standard Reports > Disk Usage, or run EXEC sp_spaceused and query sys.dm_db_file_space_usage for tempdb. If tempdb or the data drive is full, free space or grow the files before anything else. A sort that cannot get workspace can fail with allocation-related errors.
  3. Look for hardware or I/O errors. Open the SQL Server error log (Object Explorer > Management > SQL Server Logs) and Windows Event Viewer > Windows Logs > System. Look for disk warnings, controller resets, or "incorrect page" messages. On Linux, check dmesg and the SQL Server error log under /var/opt/mssql/log. If you see hardware errors, stop and involve your storage or virtualization administrator; repairing the database will not fix a failing disk.
  4. Run DBCC CHECKDB on the affected database. In a query window connected to the instance, run DBCC CHECKDB ('YourDatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS;. This checks allocation, page, and logical consistency. It can take a long time on large databases and needs free space for the internal database snapshot. Run it during a maintenance window if possible.
  5. Read the CHECKDB output carefully. If it reports zero errors, the sort failure was likely resource-related (tempdb, memory, or disk). Move to the troubleshooting section. If it reports corruption, note the object IDs, index names, and page numbers. Do not run a repair yet.
  6. Restore from backup if corruption is confirmed. The safest fix is to restore the most recent known-good backup and then apply any transaction log or differential backups. Before restoring, take a tail-log backup of the damaged database if the data is needed and the database is in FULL recovery model. Verify the restored database with DBCC CHECKDB before returning it to service.
  7. If no backup exists, run a repair as a last resort. Put the database in single-user mode, then run DBCC CHECKDB ('YourDatabaseName', REPAIR_ALLOW_DATA_LOSS) only after you understand that it can delete data. Run REPAIR_REBUILD first if CHECKDB indicates it is sufficient; it is safer but slower. After repair, run DBCC CHECKDB again and validate application data.
  8. Rebuild indexes and update statistics. After a repair or restore, rebuild fragmented indexes and update statistics so the optimizer can choose plans that do not stress sort operations. Use ALTER INDEX ... REBUILD or a maintenance plan, and UPDATE STATISTICS on affected tables.
  9. Test the original query or job. Re-run the statement that failed. If it succeeds, monitor the error log for a few days. If it fails again, capture the actual execution plan and check for large sorts that spill to tempdb.

Common Mistakes

  • Running REPAIR_ALLOW_DATA_LOSS before checking backups. It can delete rows and pages, and it is not reversible.
  • Ignoring hardware errors. If the storage layer is failing, repairs will not hold and corruption will return.
  • Running DBCC CHECKDB on a busy production server without planning for the snapshot space and I/O load.
  • Assuming error 1523 is always corruption. It can also come from tempdb exhaustion, memory pressure, or a full disk.
  • Skipping a post-repair CHECKDB. A repair can leave other inconsistencies that only a fresh check will reveal.

Tips

  • Keep tempdb on fast storage and size it adequately; multiple tempdb data files can reduce allocation contention on busy systems.
  • Schedule regular DBCC CHECKDB runs and verify backups with RESTORE VERIFYONLY.
  • Enable Page Verify (CHECKSUM) on user databases so I/O corruption is detected earlier.
  • Capture the full error text and surrounding log entries before restarting services, because logs can roll over.
  • If the error appears only for one query, examine its execution plan for large sorts and consider indexing or rewriting the query to reduce sort volume.

Troubleshooting

If DBCC CHECKDB returns no errors but the sort failure persists, focus on resources. Check SQL Server memory settings and whether the instance is under memory pressure; look for RESOURCE_SEMAPHORE waits. Confirm tempdb has free space and is not autogrowing constantly. Check the drive hosting tempdb and the data files for latency or full capacity. If the error occurs during index rebuilds, try running the rebuild with MAXDOP set to 1 to reduce workspace demand, and run it during a low-activity window. If the error appears in a job, check whether the job runs concurrently with other large sorts and whether the server has enough workspace memory. If CHECKDB reports corruption that cannot be repaired safely, restore from backup; if no backup exists, engage a data recovery specialist before running destructive repairs. After any fix, run DBCC CHECKDB again and monitor the error log for recurrence.

Frequently Asked Questions

Is error 1523 always database corruption?

No. It can be caused by tempdb exhaustion, memory pressure, disk space issues, or I/O problems. DBCC CHECKDB tells you whether corruption is present.

Can I fix error 1523 without downtime?

Possibly, if the cause is tempdb or disk space and you can free resources online. If corruption is confirmed, a restore or repair usually requires downtime.

What does REPAIR_ALLOW_DATA_LOSS actually do?

It attempts to repair allocation and consistency errors and may delete rows or pages to make the database structurally consistent. Data loss is possible, so use it only after backups are unavailable or exhausted.

Should I run DBCC CHECKDB on production?

Yes, but plan for the I/O load and snapshot space. Many organizations run it during maintenance windows or on readable secondary replicas where available.

How do I prevent sort failures in the future?

Keep tempdb sized and on fast storage, monitor disk and memory, run regular consistency checks, verify backups, and review execution plans for large sorts.