SQL Log file

  • I have 2 log files for a database(D and E drive) and i need to delete one which is in E drive. Can i do it directly or do we have some process before doing that.

  • Make sure all live transactions are stopped , if there is a transaction ongoing and writing to that log file you will not be able to delete the Log.

  • You can't delete any log file that has any portion of the active log regardless of whether there are any currently running transactions or not (stopping transactions won't change that).

    Use DBCC LOGINFO to identify which file the active portion of the log is in (VLFs with a status of 2), when all of those are in one file, you can drop the other with an ALTER DATABASE statement.

    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
  • Hi,

    1. Take backup of your databases.

    2. Detach your database after closing all active connections

    3. Attach the database using SSMS.

    4. Delete the log file that's not required from the db details pane.

    This should do it. It worked for me!!

  • menon.satyen (10/30/2012)


    Hi,

    1. Take backup of your databases.

    2. Detach your database after closing all active connections

    3. Attach the database using SSMS.

    4. Delete the log file that's not required from the db details pane.

    This should do it. It worked for me!!

    No, no, no!!!

    If the log file is deleted (or not attached), SQL could refuse to reattach the DB because either the database was not cleanly shut down or the log file that was 'not required' contained a portion of the active log.

    The correct and safe way to remove a log file is the method I gave. Any form of deleting or not attaching a log can potentially destroy the DB entirely requiring a restore from backup.

    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
  • Absolutely a NO, NO! Do not DETACH the database.

  • George M Parker (10/30/2012)


    Another potential option to use the DBCC SHRINKFILE command with an EMPTYFILE clause to clear out one of the two transaction log files by moving the active portions to the primary log file.

    No, it does not.

    As Books Online says, shrinkfile with the emptyfile option is for data files. It is used to migrate data pages to other data files in the same filegroup.

    Log records cannot be moved by anything. To drop an in-use log, you need to wait until the entire active portion of the log is in the file you want to keep (use DBCC LOGINFO) and then you can simply drop the other file (via alter database or the SSMS GUI), no other commands necessary.

    To summarise. Shrinkfile with the emptyfile option is for data files. There is nothing at all that can ever move a log record once it's written into the log file ever.

    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
  • I stand corrected and have removed the inaccurate post. Is it possible that technique worked in SQL 2000? I've confirmed exactly what you stated using a copy of the AdventureWorks2008R2 database and the EMPTYFILE clause has no effect on the transactions that exist in the 3rd file. I've confirmed it both with DBCC LOGINFO.

  • George M Parker (10/30/2012)


    Is it possible that technique worked in SQL 2000?

    No.

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

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

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