Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Failed "ALTER DATABASE...REMOVE FILE" leaves sys.database_files missing a file


Failed "ALTER DATABASE...REMOVE FILE" leaves sys.database_files missing a file

Author
Message
CaptainSlock
CaptainSlock
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 204
From SSMS I removed a secondary file (named tempdev2) in the PRIMARY filegroup of tempdb and lowered the maximum size for tempdev. It erred out saying:

The file "K:\sqldata\PROD_CRICKET\tempdev2.ndf" has been modified in the system catalog. The new path will be used the next time the database is started.
Msg 5042, Level 16, State 1, Line 1
The file 'tempdev2' cannot be removed because it is not empty.

I cancelled out of the tempdb properties and then opened them back up and noticed that my max size change was reflected and strangely, tempdev2 had disappeared. A little suspicious, I checked the file system and discovered that tempdev2 still existed. Deleting it from the OS fails, as it's still in use. I then ran DBCC SHRINKFILE(tempdev2,EMPTYFILE), but received:

Could not locate file 'tempdev2' for database 'tempdb' in sys.database_files. The file either does not exist, or was dropped.

When I look in sys.database_files, I see tempdev2 (fileid 3), but when I'm in sys.master_files I do not. Any idea what happened and more importantly, how I can resolve this without restarting the instance?

Thanks for your help.
Andre Guerreiro
Andre Guerreiro
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1065 Visits: 1514
I just had the same problem here tonight.
I was making a little test creating extra files for tempDB and ended up with this weird behavior.

Has anyone experienced this? Is this a confirmed bug?

I'm afraid of using ALTER DATABASE REMOVE FILE until I understand what's really going on. Unsure

[EDIT] For those who are having this problem you must restart your SQL Server engine process for things to show correctly. Stupid me!

Best regards,

Best regards,

Andre Guerreiro Neto

Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2/MCSE/MCSA
Noam Graizer
Noam Graizer
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 26
I am using sql server 2012 Std. Ed. and I have the same problem.
any idea ?



HanShi
HanShi
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3048 Visits: 3625
CaptainSlock (12/15/2011)
The file "K:\sqldata\PROD_CRICKET\tempdev2.ndf" has been modified in the system catalog. The new path will be used the next time the database is started.
Msg 5042, Level 16, State 1, Line 1
The file 'tempdev2' cannot be removed because it is not empty.


This message is clearly saying what has happened. The meta-data in the system tables is altered and the records related to the 'tempdev2.ndf' file has been removed. But because this file is in use by the SQL Engine itself, it can only be removed from the system after a restart of the SQL Server service.
After you have restarted the service, the file is not in use anymore (e.g. locked) and can be removed from disk.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
Noam Graizer
Noam Graizer
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 26
I reset the services - not help.
I can re-do this "alter database ...remove file" and this leaves the rows in the sys.database_files !!!
OOO !!!
I don't know what to do



Perry Whittle
Perry Whittle
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8780 Visits: 16553
Noam Graizer (7/15/2014)
I reset the services - not help.
I can re-do this "alter database ...remove file" and this leaves the rows in the sys.database_files !!!
OOO !!!
I don't know what to do

What exactly are you trying to do?
Are you trying to remove a file for tempdb or for a user database?

For tempdb you'll need to take the instance down and perform the action so that tempdb is not in use. I would start the instance in single user\restricted mode and use the following

alter database tempdb remove file logicalname

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
Pulivarthi Sasidhar
Pulivarthi Sasidhar
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1447 Visits: 989
I have faced the same issue.......Plz look into below one...

http://www.sqlservercentral.com/Forums/Topic1590255-2799-1.aspx#bm1590268


Thanks,
SP
Perry Whittle
Perry Whittle
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8780 Visits: 16553
since a restart of the instance is necessary i would recommend you just remove the file at your next maintenance window. Start the instance single user and remove it.

Note this is different to a user database

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
HanShi
HanShi
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3048 Visits: 3625
Perry Whittle (7/15/2014)
since a restart of the instance is necessary i would recommend you just remove the file at your next maintenance window. Start the instance single user and remove it.

Note this is different to a user database

For me personally setting the instance to single_user first is a bit of a overkill. Just alter the system catalog with command:
alter database tempdb remove file logicalname
...and restart the SQL Server service. That will do just fine.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
Perry Whittle
Perry Whittle
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8780 Visits: 16553
very easy to do on a maintenance window and also checks that you still know how to perform this action
;-)

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search