Removing a secondary tempdb file

  • Hello.

    I created a secondary tempdb file on our testing server the other day and i wish now to remove it.

    I have run

    Use tempdb

    alter database tempdb

    remove file tempdev2

    and i got an error saying

    The file “D:\tempdb\tempdb2.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 ‘tempdb2′ cannot be removed because it is not empty.

    When i restared the instance - sure enough the file was still there.

    Do i need to run some kind of shrink operation first ?

    Any help would be great - thanks very much

    Steven

  • TRy a shrinkfile with emptyfile, then remove the second file.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • thank you

    is this correct then :

    DBCC SHRINKFILE ('tempdev2' , emptyfile)

    then run the

    ALTER DATABASE tempdb REMOVE FILE tempdev2

  • Should work.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • apologies for this i am having problems !

    when i try to run a dbcc shrinkfile i get an error saying

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

    When i browse to the location i can see the physical file - am i ok just to delete this ?

    the properties of the database when using SSMS show the file as well !

  • I have got rid off the extra file now!!

    I then run the following to resize the original file to 650 mb and add a secondary.

    ALTER DATABASE TEMPDB

    MODIFY file

    (NAME = TEMPDEV , SIZE = 650MB

    ,MAXSIZE = UNLIMITED,

    FILEGROWTH = 10% )

    ALTER DATABASE TEMPDB

    ADD FILE (NAME = N'TempDev2',

    filename = N'D:\DEV\MSSQL10_50.dev\MSSQL\DATA\tempdb2.ndf',

    SIZE = 650 MB,

    MAXSIZE = UNLIMITED,

    FILEGROWTH = 10% )

    The second part of the code adds the file with no problems, however the first part of the code does not rezise the primary tempdev (logical name) to 650mb, it stays at 8192kb and this is after i restart the instance

  • What was the initial, defined size of the first file before you ran that?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • The initial size was 8mb - i obtained that info from the database properties by right clikcing in ssms - unless there is a better way ?

  • Can anybody please advise on the last few comments ? The original file has not grown when i restart the sql server instance - the second file has been added and sized correctly. The code i typed was:

    ALTER DATABASE TEMPDB

    MODIFY file

    (NAME = TEMPDEV , SIZE = 650MB

    ,MAXSIZE = UNLIMITED,

    FILEGROWTH = 10% )

    ALTER DATABASE TEMPDB

    ADD FILE (NAME = N'TempDev2',

    filename = N'D:\DEV\MSSQL10_50.dev\MSSQL\DATA\tempdb2.ndf',

    SIZE = 650 MB,

    MAXSIZE = UNLIMITED,

    FILEGROWTH = 10% )

    The original size of the primary file was 8mb - when the server started again it was still 8mb and not 650mb. I have noticed that we only have Service Pack 1 installed - would this be the reason the file is not growing to 650mb when i restart the server ? (By the way when i say restart the server i dont mean a hard reboot i just mean by clicking restart on the instance)

  • PearlJammer1 - Thursday, February 28, 2013 8:02 AM

    apologies for this i am having problems !when i try to run a dbcc shrinkfile i get an error saying "Could not locate file 'tempdev2' for database tempdb in sys.database_files. The file either does not exist or was dropped.When i browse to the location i can see the physical file - am i ok just to delete this ?the properties of the database when using SSMS show the file as well !

    I was reading the thread and saw that you didn't explain how you removed the additional tempdev file. For anyone else reading this thread, removing the quotes from tempdev2 should fixed it.
    DBCC SHRINKFILE (tempdev2, emptyfile)
    ALTER DATABASE tempdb REMOVE FILE tempdev2
    FYI, in SQL 2017 the additional files is now named tempdb_mssql_2 instead of tempdev2.

Viewing 10 posts - 1 through 9 (of 9 total)

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