Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Failed "ALTER DATABASE...REMOVE FILE" leaves sys.database_files missing a file Expand / Collapse
Author
Message
Posted Thursday, December 15, 2011 5:15 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 22, 2014 4:04 PM
Points: 1, Visits: 158
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.
Post #1222816
Posted Wednesday, January 11, 2012 2:27 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, September 12, 2014 5:33 AM
Points: 900, Visits: 1,489
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.

[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
Post #1234388
Posted Tuesday, July 15, 2014 2:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 1:53 PM
Points: 4, Visits: 21
I am using sql server 2012 Std. Ed. and I have the same problem.
any idea ?



Post #1592450
Posted Tuesday, July 15, 2014 3:07 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:47 AM
Points: 2,304, Visits: 2,770
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’! **
Post #1592457
Posted Tuesday, July 15, 2014 3:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 1:53 PM
Points: 4, Visits: 21
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



Post #1592464
Posted Tuesday, July 15, 2014 5:17 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 6,365, Visits: 13,692
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"
Post #1592512
Posted Tuesday, July 15, 2014 6:19 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 3:03 AM
Points: 1,062, Visits: 708
I have faced the same issue.......Plz look into below one...

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


Thanks,
SP
Post #1592519
Posted Tuesday, July 15, 2014 7:10 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 6,365, Visits: 13,692
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"
Post #1592541
Posted Tuesday, July 15, 2014 7:55 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:47 AM
Points: 2,304, Visits: 2,770
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’! **
Post #1592575
Posted Tuesday, July 15, 2014 8:06 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 6,365, Visits: 13,692
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"
Post #1592584
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse