Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Im a bit confused was the TRUNCATEONLY parameter changed in 2012 or is the documentation wrong in 2008R2?

2008R2

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 statment 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 statment now tells me it only affects the log file?

So was the functionality changed or is there a error in the documentation or is my interpretation wrong?

share|improve this question
add comment

2 Answers

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 the what happens using TRUNCATEONLY with SHRINKDATABASE. Here is a run down of what happened to a database called performance that I have installed locally.

SELECT @@VERSION
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)   Jun 28 2012 08:36:30   Copyright (c) Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) 

use performance

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.

FileId      FileSize             StartOffset          FSeqNo      Status      Parity CreateLSN
----------- -------------------- -------------------- ----------- ----------- ------ ---------------------------------------
2           253952               8192                 23          2           64     0
2           253952               262144               24          2           64     0
2           270336               516096               25          2           64     24000000013400005

I then ran DBCC SQLPERF(LOGSPACE) and got the following output

dbcc sqlperf(logspace)
/*
Database Name   Log Size (MB)   Log Space Used (%)  Status
Performance 9870,867    3,395626    0
*/

I then ran

DBCC SHRINKDATABASE(PERFORMANCE, truncateonly) 

and got the following result

/*
DbId    FileId  CurrentSize MinimumSize UsedPages   EstimatedPages
8   1   66464   288 44944   44944
8   2   116584  72  116584  72
*/

Next, I reran

dbcc sqlperf(logspace) 

and got

/*
Database Name   Log Size (MB)   Log Space Used (%)  Status
Performance 910,8047    37,08699    0
*/

SHRINKDATABASE with TRUNCATEONLY gave back over 9GB of available space in the transaction log file to the OS.

I tried the same experiment with another database called performance2

sp_spaceused

/*
Performance2 52.19 MB   22.81 MB
*/


DBCC SHRINKDATABASE(Performance2, truncateonly)

sp_spaceused

/*
database_name   database_size   unallocated space
Performance2 31.13 MB   21.13 MB
*/

Which gave back 20MB to the OS. Using SQL Server 2008, SHRINKDATABASE TRUNCATEONLY shrinks both data and transaction log files.

share|improve this answer
add comment

I just tested with a scratch database, and using the TRUNCATEONLY option caused both the data file and log file to be shrunk.

I believe what they're trying to clarify is that the TRUNCATEONLY option changes the behavior when shrinking the data file (i.e. don't rearrange any data pages, just chop off the unused space at the end), but the log file will still be shrunk normally.

If my understanding of the option is correct, then this is probably a better way to describe it:

The log file will still be shrunk normally when using the TRUNCATEONLY option. This option only affects the behavior when shrinking data files. To truncate only the data file, use DBCC SHRINKFILE.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.