Im a bit confused. Was the TRUNCATEONLY
parameter changed in SQL 2012 or is the documentation wrong in SQL 2008 R2?
2008 R2
Releases all free space at the end of the file to the operating system,
but does not perform any page movement inside the file. The data file
is shrunk only to the last allocated extent. target_percent is ignored
if specified with TRUNCATEONLY.TRUNCATEONLY is applicable only to data files. The log files are not
affected.
The last statement makes me thing this has no effect on log files at all?
2012
Releases all free space at the end of the file to the operating system,
but does not perform any page movement inside the file. The data file
is shrunk only to the last allocated extent. target_percent is ignored
if specified with TRUNCATEONLY.TRUNCATEONLY affects the log file. To truncate only the data file, use
DBCC SHRINKFILE.
The last statement now tells me it only affects the log file?
So was the functionality changed, or is there an error in the documentation, or is my interpretation wrong?
Best Answer
TRUNCATEONLY affects both the LOG and the DATA files in 2008. On BOL for SQL Server 2012 the message simply indicates that if you only wish to SHRINK the database file, then you should use DBCC SHRINKFILE which will allow you to shrink either the data or log files.
For 2008, it is clearly indicated that TRUNCATEONLY only affects DATA files.
Lets test. To visualize what happens using
TRUNCATEONLY
withSHRINKDATABASE
, here is a run down of what happened to a database calledperformance
that I have installed locally.I ran
DBCC LOGINFO
just to take a peak inside the transaction log and found that all of the virtual log files after about 200 were inactive, status = 0. In my performance database, all those inactive VLFs can be truncated and the space can be given back to the OS.Here is some sample output from LOGINFO.
I then ran
DBCC SQLPERF(LOGSPACE)
and got the following outputI then ran
and got the following result
Next, I reran
and got
SHRINKDATABASE
withTRUNCATEONLY
gave back over 9 GB of available space from the transaction log file back to the OS.I tried the same experiment with another database called
performance2
Which gave back 20 MB to the OS. Using SQL Server 2008,
SHRINKDATABASE TRUNCATEONLY
shrinks both data and transaction log files.