SQL Server – Reducing Database File Size: DBCC Shrinkfile vs Data Compression

database-tuningperformancesql server

I need to reduce the size of Database file. I am confused between DBCC Shrinkfile and Data compression option.

DBCC shrinkfile will reduce the actual database file size as far as I know but Data compression will not do the same. please advice or their are any other options because I cannot delete any file from my prod DB.

Best Answer

  1. DBCC SHRINKFILE will release unused but allocated space. From books online: DBCC SHRINKFILE does not shrink a file past the size needed to store the data in the file. For example, if 7 MB of a 10-MB data file is used, a DBCC SHRINKFILE statement with a target_size of 6 shrinks the file to only 7 MB, not 6 MB.

  2. The data compression feature in SQL Server helps compress the data inside a database, and it can help reduce the size of the database. Apart from the space savings, data compression provides another benefit: Because compressed data is stored in fewer pages, queries need to read fewer pages from the disk, thereby improving the performance of I/O intensive workloads. However, extra CPU resources are required on the database server to compress and decompress the data, while data is exchanged with the application. Therefore, it is important to understand the workload characteristics when deciding which tables to compress. Compression will not release allocated space. You can do so by shrinking the file once you compress. Ref: https://technet.microsoft.com/en-us/library/dd894051(v=sql.100).aspx

  3. See the answer to this question here asked earlier.