Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

DBCC SHRINKFILE not recaliming the free disk space in a datafile but throwing error

$
0
0

Hi,

Despite this is an huge narration, in order to get a solution, I should mention the background of this database file on which DBCC SHRINKFILE is getting failed.

We have a SQL Server database file with the capacity of 270 Gigs& the database name is: "MyDataFile270G

The Logical Name of the Database files are as : MyDataFile.mdf ;MyDataFile_log.ldf

We planned to split this huge Data file (MyDataFile.mdf, 270 Gigs) into 4 Data files (MyDataFile1.mdf, MyDataFile2.ndf, MyDataFile3.ndfand MyDataFile4.ndf to implement multiple data files on separate 4 disk drives.

We decided to use DBCC SHRINKFILE'S EMPTY FILE OPTION and the following are the workouts for this plan.

Step 1)  We changed the Logical Database name ofMyDataFile.mdf from MyDataFile to MyDataFile1, so I used the following command

alter database MyDataFile270G set SINGLE_USER with rollback immediate
go
alter database MyDataFile270G modify file (NAME=N'MyDataFile',NEWNAME=N'MyDataFile1')
GO
alter database MyDataFile270G set MULTI_USER with rollback immediate
go

Step 2) To CREATE A TEMPORARY DATABASE FILE, We used the following Script:

USE [master]
GO
ALTER DATABASE MyDataFile270G ADD FILE (
   NAME = 'MyDataFile_TEMP',
   FILENAME = 'N:\SQLData\MyDataFile_TEMP.ndf',
   SIZE = 270GB,
   FILEGROWTH = 1GB
);
GO

Step 3) Using the following command, We moved the entire data fromMyDataFile1 to MyDataFile_TEMP

USE MyDataFile270G
GO
DBCC SHRINKFILE (N'MyDataFile1' , EMPTYFILE)
GO

It took around 36 hours to complete Step 3 and as we were in a compulsion to bring the database ONLINE, we stopped the plan in this stage and handed over the database with the following capacity details:

MyDataFile1 with 270 Gigs & MyDataFile_TEMP with 270 Gigs. As this is online now, the present Used & Free space details are as follows:

MyDataFile1 : Used - 5 Gigs ; Free - 265 Gigs

MyDataTemp : Used : Almost all the 270 Gigs,

Here we go for the error message that I am facing whilst trying to SHRINK the Data File MyDataFile1 in order to regard 195 Gigs out of 265 Gigs since we planned to have each data file with 70 Gigs.

The Shrink command I am trying to use:

USE MyDataFile270G
GO
DBCC SHRINKFILE (N'MyDataFile1' , 71680)
GO

The following error message is being received for the above mentioned shrink command:

Msg 8985, Level 16, State 1, Line 4
Could not locate file 'MyDataFile1' for database 'MyDataFile270G ' in sys.database_files. The file either does not exist, or was dropped.

Any solution to overcome this issue and regain the disk space from MyDataFile1is very much appreciated.

Thanks in advance.


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>