SQL Server Error 1535: Cannot Share Extent – Fix Guide
In this article
SQL Server error 1535 (“Cannot share extent. Shared extent directory is full.”) occurs when the database engine cannot allocate a new shared extent because the shared extent directory (the internal structure that tracks shared extents) has reached its size limit. This typically happens in databases that use shared extents, such as those with sparse files or certain columnstore indexes. The fix involves identifying the cause, freeing space, and possibly adjusting file growth settings or rebuilding the affected index. Before you begin, ensure you have a recent backup and the necessary permissions (sysadmin or db_owner) to run the required commands.
What You'll Need
- SQL Server Management Studio (SSMS) or Azure Data Studio, or the sqlcmd utility.
- Sysadmin or db_owner permissions on the affected database.
- A recent full backup of the database (recommended before any repair or rebuild).
- Access to the SQL Server error log and Windows Event Viewer for additional context.
Step-by-Step
- Confirm the error and identify the affected database. Check the SQL Server error log or the application that received the error. The message will include the database name and possibly the file or object involved. Run the following query to see recent errors:
This reads the current error log for entries containing “1535”. Note the database name and any accompanying details.EXEC sp_readerrorlog 0, 1, N'1535'; - Check the size and free space of the database files. Use the following query to see file sizes and available space:
Replace [YourDatabaseName] with the actual database name. If free space is very low (less than 10% of file size), the shared extent directory may be full because the file cannot grow or has hit a maximum size.USE [YourDatabaseName]; SELECT name, size/128.0 AS SizeMB, FILEPROPERTY(name, 'SpaceUsed')/128.0 AS UsedMB, (size - FILEPROPERTY(name, 'SpaceUsed'))/128.0 AS FreeMB FROM sys.database_files; - Verify the file growth settings. Run:
If max_size is set to a value that is already reached, or if growth is disabled (0), the file cannot expand. Note: growth values are in 8-KB pages; 0 means no growth. To allow growth, use ALTER DATABASE ... MODIFY FILE (see next step).SELECT name, growth, is_percent_growth, max_size FROM sys.database_files; - Increase the file size or enable growth. If the file has a max_size limit, you can increase it or set it to UNLIMITED (if disk space allows). For example:
Or to grow the file immediately:ALTER DATABASE [YourDatabaseName] MODIFY FILE (NAME = N'LogicalFileName', MAXSIZE = UNLIMITED);
Replace LogicalFileName with the logical name from sys.database_files. Ensure the disk has enough free space before growing.ALTER DATABASE [YourDatabaseName] MODIFY FILE (NAME = N'LogicalFileName', SIZE = 1024MB); - Free up space inside the database. If the file cannot grow due to disk constraints, remove unnecessary data. Consider:
- Deleting old records or archiving them to another database.
- Rebuilding or reorganizing indexes to reclaim space (use ALTER INDEX ... REBUILD or REORGANIZE).
- Shrinking the file only as a last resort (DBCC SHRINKFILE), but note that shrinking can cause fragmentation and should be used sparingly.
- Rebuild the affected index or object. If the error points to a specific index (often a columnstore index), rebuilding it can resolve the issue by recreating the shared extents. Use:
For a columnstore index, consider using REBUILD with PARTITION = ALL if partitioned. This operation requires free space in the filegroup.ALTER INDEX [IndexName] ON [Schema].[Table] REBUILD; - Check for sparse files or filegroups with shared extents. Shared extents are used by sparse files (e.g., for database snapshots) and some columnstore structures. If you have a database snapshot, consider dropping it if no longer needed. To list snapshots:
Dropping a snapshot frees shared extents. Use DROP DATABASE [SnapshotName].SELECT name, source_database_id FROM sys.databases WHERE source_database_id IS NOT NULL; - Restart SQL Server if the issue persists. In rare cases, internal metadata may be inconsistent. Restarting the SQL Server service (via SQL Server Configuration Manager or Services) can clear transient issues. Ensure you have a maintenance window.
- Run DBCC CHECKDB for consistency. If the error continues, check database integrity:
If errors are reported, follow the recommended repair steps (e.g., REPAIR_ALLOW_DATA_LOSS) only after consulting with a professional and ensuring backups are available.DBCC CHECKDB ([YourDatabaseName]) WITH NO_INFOMSGS;
Common Mistakes
- Ignoring disk space: Increasing max_size or file size without checking available disk space can lead to further errors or OS-level issues.
- Shrinking the database unnecessarily: Shrinking files to free space often causes fragmentation and does not address the root cause of shared extent exhaustion.
- Not backing up before repairs: Running DBCC CHECKDB with repair options or rebuilding indexes without a backup can risk data loss.
- Overlooking snapshots: Database snapshots consume shared extents; forgetting to drop unused snapshots leaves the directory full.
- Assuming the error is corruption: Error 1535 is usually an allocation issue, not corruption; jumping to repair steps can be unnecessary and risky.
Tips
- Monitor file growth and free space regularly using SQL Server Agent alerts or custom scripts.
- Set appropriate autogrowth settings (e.g., fixed MB increments rather than percentage) to avoid frequent small growths.
- Keep database snapshots only as long as needed; they consume shared extents and can fill the directory.
- For columnstore indexes, consider partitioning and using compressed rowgroups to reduce extent usage.
- Use the sys.dm_db_file_space_usage DMV to track space usage within files.
Troubleshooting
If the error persists after following the steps, try these additional checks:
- Check for filegroup fullness: If the filegroup containing the shared extents is full, add a new file to the filegroup or increase the size of existing files. Use ALTER DATABASE ... ADD FILE.
- Review the SQL Server error log for related errors: Look for errors 1101, 1105, or 9002 that indicate space issues.
- Consider trace flag 1117 or 1118: These trace flags control autogrowth behavior for tempdb and user databases; consult Microsoft documentation before enabling.
- Contact Microsoft Support: If the issue is reproducible and none of the above works, open a support case with Microsoft, providing the error log and details of your environment.
Frequently Asked Questions
What causes SQL Server error 1535?
Error 1535 occurs when the shared extent directory, which tracks shared extents used by sparse files and certain columnstore indexes, is full and cannot allocate a new extent. This is typically due to insufficient free space in the database file or a reached max_size limit.
Can I fix error 1535 without restarting SQL Server?
Yes, in most cases. Freeing space, increasing file size, or rebuilding the affected index resolves the issue without a restart. Restarting is a last resort.
Does error 1535 indicate database corruption?
No, error 1535 is an allocation error, not a corruption error. It means the shared extent directory is full, not that data is damaged. However, running DBCC CHECKDB is a good practice to rule out other issues.
How do I check if my database uses shared extents?
Shared extents are used by sparse files (e.g., database snapshots) and columnstore indexes. You can check for snapshots with sys.databases and for columnstore indexes with sys.indexes where type = 5 or 6.
Can I prevent error 1535 from happening again?
Yes, by monitoring free space, setting appropriate autogrowth, avoiding unnecessary snapshots, and regularly maintaining indexes to prevent excessive fragmentation and space usage.
What should I do if I don't have enough disk space to grow the file?
Free up space by archiving or deleting old data, moving the database to a larger disk, or adding a new file on a different disk to the filegroup. Shrinking is a temporary fix but not a long-term solution.