Troubleshooting Guide: SQL Server Error 5015 — “ALTER DATABASE failed. The total size specified must be 1 MB or greater.”
Why This Error Happens
This error occurs when an ALTER DATABASE statement attempts to resize a data or log file (via MODIFY FILE with a SIZE parameter) to a value smaller than the required 1 MB minimum, often due to a miscalculated value passed in KB instead of MB. It can also occur when automated scripts or maintenance jobs reference a stale or incorrect file size variable, or when a file’s FILEGROWTH and SIZE settings conflict after a prior shrink operation. Additionally, corrupted or improperly restored database metadata in sys.master_files can cause SQL Server to misread the current file size, triggering this validation error during the next resize attempt.
Step-by-Step Resolution Guide
Step 1: Review the Exact ALTER DATABASE Statement
- Open SQL Server Management Studio (SSMS) or Azure Data Studio and locate the exact T-SQL script that triggered the error.
- Check the
SIZE =clause — ensure the value is specified in MB (e.g.,SIZE = 50MB, notSIZE = 50KB). - Example of a problematic statement:
ALTER DATABASE SalesDB MODIFY FILE (NAME = SalesDB_log, SIZE = 512KB);
- Correct it to:
ALTER DATABASE SalesDB MODIFY FILE (NAME = SalesDB_log, SIZE = 1MB);
Step 2: Check Current File Sizes in sys.master_files
- Run the following query to inspect current file sizes and growth settings:
SELECT name, size, growth, is_percent_growth
FROM sys.master_files
WHERE database_id = DB_ID('SalesDB');
- Confirm the
sizecolumn (in 8 KB pages) correctly reflects the actual file size on disk atC:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA\. - If values appear mismatched or corrupted, note the discrepancy for the next step.
Step 3: Correct the ALTER DATABASE Command with Valid Minimums
- Re-issue the command ensuring the new size is strictly greater than or equal to 1 MB and greater than the current committed size if growing the file:
ALTER DATABASE SalesDB
MODIFY FILE (NAME = SalesDB_log, SIZE = 5MB, FILEGROWTH = 10%);
- If resizing a log file after a shrink operation, first run
DBCC SQLPERF(LOGSPACE)to confirm actual log usage before setting a new size.
Step 4: Validate Disk Space and File Permissions
- Confirm the SQL Server service account (e.g.,
NT Service\MSSQLSERVER) has write permissions on the target data/log directory. - Check available disk space on the volume hosting the
.mdf/.ldffiles using File Explorer orGet-PSDrivein PowerShell. - Restart the SQL Server service via Services.msc or
net stop MSSQLSERVER && net start MSSQLSERVERif permission changes were made.
Alternative or Verification Steps
- After applying the corrected
ALTER DATABASEstatement, re-runSELECT name, size FROM sys.master_files WHERE database_id = DB_ID('SalesDB');to confirm the new size is reflected and no errors are returned. - If the error persists despite correct syntax, restore the database from a known-good backup to a test instance and compare file metadata, as this may indicate underlying corruption in the database’s file structure.