Sql Server : Error Message : DBCC SHRINKDATABASE: File ID 1 of database ID 2 was skipped because the file does not have enough free space to reclaim.
- Posted by Sqltimes
- On March 28, 2015
- 0 Comments
Quick one today:
A few weeks ago, I ran into an interesting error message:
Error Message:
DBCC SHRINKDATABASE: File ID 1 of database ID 2 was skipped because the file does not have enough free space to reclaim. DBCC SHRINKDATABASE: File ID 2 of database ID 2 was skipped because the file does not have enough free space to reclaim. DBCC execution completed. If DBCC printed error messages, contact your system administrator.
After looking into it a bit further, these are the conclusions.
- SHRINKDATABASE runs on the entire database, unlike SHRINKFILE. So, when I issued the command, the command internally tried to SHRINK both data and log file. The shrink percentage parameter indicates the amount of “shrink” that it is attempting on the database (data & log file). If there is not enough free space inside the data or log file, then Sql Server throws this error out saying it could not proceed. If the expected free space is not available on both the files, the command errors out.
- SHRINKDATABASE cannot reduce the data and log file size beyond the initially configured number. This could also be a factor.
So, first we need to understand how much free space is available, so I could shrink based on that. For that use the following command:
1
2
3
4
5
|
-- -- How much free space is available -- DBCC SHRINKDATABASE (SampleDB, TABULAR) GO |
This give output in the following format:
DbId | FileId | CurrentSize | MinimumSize | UsedPages | EstimatedPages |
2 | 1 | 163392 | 1024 | 552 | 496 |
2 | 2 | 27408 | 64 | 27408 | 64 |
Once you know how much free space is available, then you could re-run the SHRINKDATABASE command with pertinent parameter values.
Note:
- Running SHRINKDATABASE command on production systems is not advisable. Careful analysis needs to happen before any steps are taken.
- Also, this (TABULAR) option is an undocumented feature, so it could change in future
Hope this helps,
0 Comments