Jul
24
2015

Shrink Data file failed with Error 3140

While shrinking a large (950GB) database file to move data to a secondary NDF, got below 3140 error, it is a normal error occurs while shrinking files of that capacity, please find resolution below,

 

Error:

 

Environment: SQL Server 2005 ENT. ed.

 

Issue:

Data file shrink fails for large data file size with Error: 3140

 

Fix:

The following example query truncates the primary data file in the AdventureWorks2008R2 database. The sys.database_files catalog view is queried to obtain the file_id of the data file.

 

USE AdventureWorks2008R2;

GO

SELECT file_id, name

FROM sys.database_files;

GO

DBCC SHRINKFILE (1, TRUNCATEONLY);

 

After executing above query, try to shrink database file again which should resolve the issue.

 

DBCC SHRINKFILE SYNTAX:

DBCC SHRINKFILE

(

    { file_name | file_id }

    { [ , EMPTYFILE ]

    | [ [ , target_size ] [ , { NOTRUNCATE | TRUNCATEONLY } ] ]

    }

)

[ WITH NO_INFOMSGS ]

 

 

TRUNCATEONLY:

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_size is ignored if specified with TRUNCATEONLY
  • TRUNCATEONLY is applicable only to data files
  • That means if you have even 1 data page which is not empty at the end you won’t see and space freed….

 

References:

https://technet.microsoft.com/en-us/library/ms189493%28v=sql.105%29.aspx

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6580e74f-51bc-4648-95c9-4440f5b19619/dbcc-shrinkfile-logicalfilename5-showing-error?forum=sqldatabaseengine

https://technet.microsoft.com/en-us/library/ms189493%28v=sql.105%29.aspx

Download PDF

About the Author: Nitin G

Indian born, trekker, biker, photographer, lover of monsoons. I've been working full time with SQL Server since year 2005 and blogs to post the content aquired during my research on new topics or fixing issues faced by me as a DBA while working in different kind of projects, hope some of my posts may helps others in SQLDBA community. Everything you read on my blog is my own personal opinion and any code is provided "AS-IS" with no warranties!

Leave a comment

Subscribe to this blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 195 other subscribers

Translate this blog!

EnglishFrenchGermanItalianPortugueseRussianSpanish

Calender

August 2019
M T W T F S S
« Nov    
 1234
567891011
12131415161718
19202122232425
262728293031  

View Post by Categories

%d bloggers like this: