SQL Server Error 1137 occurs when a database attempts to grow its data or log file, but the number of files associated with that specific filegroup has reached the maximum limit allowed by the system. To resolve this, you must either add a new filegroup and move data to it, consolidate existing files, or increase the size of existing files to prevent further automatic growth triggers. This error typically happens in environments with many small data files or aggressive autogrowth settings on a limited number of disks.

What You'll Need

  • Administrative access to the SQL Server instance (sysadmin role).
  • SQL Server Management Studio (SSMS) installed and connected to the instance.
  • Knowledge of the current disk space available on the drives hosting the database files.
  • A current full backup of the database before performing structural changes.

Step-by-Step

  1. Identify the Affected Filegroup: Open SQL Server Management Studio and run a query against sys.database_files to see which filegroup is hitting the limit. Look for the filegroup that has the highest number of files associated with it. You can use the query SELECT data_space_id, COUNT(*) FROM sys.database_files GROUP BY data_space_id to identify the problematic group.
  2. Check Current File Counts: Verify the total number of files. SQL Server has a hard limit of 32,767 files per database, but practical performance limits and specific filegroup constraints often trigger Error 1137 much sooner if the system cannot allocate a new file during an autogrowth event.
  3. Disable Autogrowth Temporarily: To prevent the database from crashing or entering a read-only state while you work, manually expand the existing files. Right-click the database in Object Explorer, select Properties, and navigate to the Files page. Increase the initial size of the largest files in the affected filegroup to provide immediate breathing room.
  4. Create a New Filegroup: Since you cannot add more files to the current filegroup, you must create a new one. Right-click the database > Properties > Filegroups. Click Add and give the new filegroup a descriptive name (e.g., "DATA_GROUP_02").
  5. Add Files to the New Filegroup: Now that the new group exists, add one or more data files (.ndf) to this new group. Go to the Files page in Properties, click Add, and ensure the Filegroup dropdown is set to your newly created group. Specify a path on a drive with sufficient space.
  6. Migrate Data to the New Filegroup: To reduce the pressure on the original filegroup, move large tables or indexes to the new filegroup. This is done by recreating the clustered index on the new filegroup. Use the command: CREATE CLUSTERED INDEX IX_YourTable ON YourTable(YourColumn) WITH (DROP_EXISTING = ON) ON [DATA_GROUP_02];
  7. Consolidate Small Files: If the error was caused by having too many small files, identify the smallest files in the original filegroup. Use the DBCC SHRINKFILE command to empty them, then remove them from the database using ALTER DATABASE [DbName] REMOVE FILE [FileName];.
  8. Adjust Autogrowth Settings: Once the file count is reduced or the load is spread across multiple filegroups, change the autogrowth settings from a small percentage (like 10%) to a fixed size (like 256MB or 1024MB). This prevents the system from frequently attempting to grow files, which reduces the risk of hitting file limits during peak traffic.

Common Mistakes

One of the most common mistakes is attempting to simply increase the size of the primary file without addressing the underlying file count. If the error is specifically about the number of files, increasing the size of one file helps temporarily, but it does not solve the structural limit if the database is configured to create new files automatically via a specific script or third-party tool. Another mistake is moving data to a new filegroup on the same physical disk without checking I/O throughput. While this solves Error 1137, it can create a performance bottleneck because the disk head must still jump between multiple files on the same platter or SSD controller.

Users also frequently forget to take a backup before running CREATE CLUSTERED INDEX... WITH (DROP_EXISTING = ON). While this operation is generally safe, it is a resource-intensive process that locks the table. If the process is interrupted or the disk runs out of space mid-migration, the database could be left in an inconsistent state. Finally, avoid using the default "Auto-grow" percentage for very large databases; as the file grows, a 10% growth on a 1TB file is 100GB, which can cause massive timeouts and transaction log bloat.

Tips

For optimal performance, try to keep the number of files per filegroup equal to the number of logical processors in your server, up to a maximum of 8. Having hundreds of files in a single filegroup often leads to the Error 1137 scenario and degrades performance due to the overhead of managing so many file handles. If you find yourself frequently hitting file limits, consider implementing a partitioning strategy. Partitioning allows you to spread data across different filegroups based on a range (like date), which naturally organizes your files and prevents any single filegroup from becoming overloaded.

Always monitor your sys.master_files and sys.database_files views using a scheduled alert. You can set up a SQL Server Agent job that sends an email notification when the number of files in any filegroup reaches 80% of your internal organizational limit. This allows you to perform the migration to a new filegroup during a planned maintenance window rather than responding to a production outage caused by Error 1137.

Troubleshooting

If you have added a new filegroup and migrated data, but the error persists, check if the error is actually occurring on the transaction log (LDF) rather than the data files (MDF/NDF). While the log usually consists of a single file, certain configurations or mirrored setups can cause issues. Ensure the log file has enough disk space to grow and that it is not capped by a MAXSIZE setting.

If you cannot move data because the tables are too large and you lack the disk space to create a second copy during the index rebuild, you may need to use a "shrink and grow" strategy. Shrink the least-used files in the original filegroup to free up space on the disk, then use that reclaimed space to expand the primary files. If the database is in a "Read-Only" state due to the error, you must first set the database to MULTI_USER and READ_WRITE mode using ALTER DATABASE [DbName] SET READ_WRITE; before any of the structural changes can be applied.

In cases where the files are fragmented across the disk, the OS might report available space that SQL Server cannot use for a contiguous growth operation. If you see plenty of disk space but still receive growth errors, run a disk defragmentation tool (if using HDD) or check for filesystem-level quotas that might be restricting the SQL Server service account from creating new files.

Frequently Asked Questions

What is the maximum number of files allowed in SQL Server?

SQL Server supports up to 32,767 files per database. However, Error 1137 usually occurs when a specific limit within a filegroup or a system resource constraint is hit, or when the configuration prevents the addition of more files.

Does adding a new filegroup slow down the database?

No, adding a new filegroup generally does not slow down the database. In fact, if you place the new filegroup on a separate physical disk, it can improve performance by increasing I/O parallelism.

Can I merge two data files into one?

There is no direct "merge" command. You must move the data from one file to another by recreating indexes or moving tables to a different filegroup, and then remove the empty file using the REMOVE FILE command.

Will shrinking a file fix Error 1137?

Shrinking a file does not reduce the number of files, which is what Error 1137 is about. However, shrinking a file allows you to delete that file entirely, which reduces the count and resolves the error.

Is this error related to disk space?

Indirectly, yes. While Error 1137 is about the count of files, it is often triggered when SQL Server tries to create a new file because the existing ones cannot grow due to disk space limitations.

Do I need to restart SQL Server after adding a filegroup?

No, adding filegroups and files is an online operation. You do not need to restart the SQL Server service for these changes to take effect.