Shrinking DOES NOT means compressing, shrinking in SQL Server means, removing empty space from database files and releasing the empty space either to operating system or to SQL Server.
Shrink command is a logged operation, When we perform Shrink operation, this information is logged in log file, and if there is no empty space in log file, SQl Server cannot write to log file because there is no empty space in logfile and that is why you cannot shrink a database in that case.
Shrinking best practices:
1. Use DBCC Shrinkfile (‘Filename’, Estimated_File_Size_After_Shrink (in MB) ) instead of DBCC Shrinkdatabase command.
2. Do not shrink file/database in big intervals, shrink in small intervals and issue shrink command multiple times For example shrink individual database files in smaller chunks, say 50 MB at a time.
DBCC SHRINKFILE (DataFil1, 25000)
go
DBCC SHRINKFILE (DataFil1, 25950)
go
...and so on...
3. Do not shrink your database when running backup jobs, otherwise backup jobs will fail.
4. Always Rebuild your indexes after you shrink database, because shrinking rearrange datapages, that means fragmentation, Clustered index can only be rebuild.
What are the USEDPAGES & ESTIMATEDPAGES that appear on the Results Pane after using the DBCC SHRINKDATABASE?
UsedPages: The number of 8-KB pages currently used by the file.
EstimatedPages: The number of 8-KB pages that SQL Server estimates the file could be shrunk down to.
No comments:
Post a Comment