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

  • 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.

  • 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

  • I am using sql server 2012 Std. Ed. and I have the same problem.

    any idea ?

  • 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’! **
  • 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

  • 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" 😉

  • I have faced the same issue.......Plz look into below one...

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

    Thanks,

    SP

  • 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" 😉

  • 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’! **
  • 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" 😉

  • finally we found the correct solution:

    after you remove file from the DB, you have to backup log

    this reset the sys.database_files table

    now we successed to add files ...

  • Noam Graizer (7/15/2014)


    finally we found the correct solution:

    after you remove file from the DB, you have to backup log

    this reset the sys.database_files table

    now we successed to add files ...

    For a user database, yes?

    In simple mode a checkpoint clears the file list

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

    "Ya can't make an omelette without breaking just a few eggs" 😉

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply