Moving Transaction Log Files and Attaching in SQL 2000

  • It is my understanding that the database files and the log files should be on separate drives.

    I understand that I need to DETACH the database, copy the log file to the new location, and then ATTACH the database.

    I need specifics on how to copy the log file to the new location and then tell the database when you attach it, that the log files are now on another drive.

    Thank you.

  • Keeping mdb and ldf files on separate physical disks is considered a best practice.

    See:

    http://msdn.microsoft.com/en-us/library/ms187858.aspx

    for information on how to attach and detatch database and log files.

    While the specific syntax you need is not listed in this article, you should be able to use the example code to figure this out for yourself.

    dwagnon (6/20/2008)


    It is my understanding that the database files and the log files should be on separate drives.

    I understand that I need to DETACH the database, copy the log file to the new location, and then ATTACH the database.

    I need specifics on how to copy the log file to the new location and then tell the database when you attach it, that the log files are now on another drive.

    Thank you.

    Brad M. McGehee
    DBA

  • So you are saying that after we detach the database, we use a create statement showing where the *.mdf and *.ldf files go?

  • Use sp_attach_db with the same .mdf/.ldf files. Simply put one of them on a separate physical disk(s) and your path statements in sp_attach_db should reflect those paths.

    -- You can't be late until you show up.

  • Hi,

    Consider if you are planning to move log files from C: drive to D: drive. Lets assume the db name is TEST, you need to detach the db, move the log file to a new location and attach.

    *) Detach the database. Use SP_Detach_db procedure

    *) Move the log file alone from C: drive to D: drive

    *) Attach the db using SP_attach_db procedure as shown below

    sp_attach_db 'TEST','C:\sql\test.mdf','D:\sql\test_log.ldf'

  • That seems to work although the database cannot be seen in Enterprise Manager. Is there another step to have the database show?

  • Thank you all. We have it working now.

  • Thank you all for your help. What we were missing was after copying the log file to the new disk drive, we were not deleting it from the old drive, when we tried to "attach" there were log scan errors. Once we deleted the "old" log file everything worked great!!

    Thanks again from a very new SQL person!!!

  • I have actually made this same mistake myself, more than once. It is not always easy to remember to delete the old file.

    dwagnon (6/25/2008)


    Thank you all for your help. What we were missing was after copying the log file to the new disk drive, we were not deleting it from the old drive, when we tried to "attach" there were log scan errors. Once we deleted the "old" log file everything worked great!!

    Thanks again from a very new SQL person!!!

    Brad M. McGehee
    DBA

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

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