How do I decrease the size of my sql server log file?

前端 未结 6 868
梦谈多话
梦谈多话 2020-12-04 13:08

So I have been neglecting to do any backups of my fogbugz database, and now the fogbugz ldf file is over 2 and half gigs. Thats been built up over the six months we\'ve been

6条回答
  •  日久生厌
    2020-12-04 14:04

    I had the same problem, my database log file size was about 39 gigabyte, and after shrinking (both database and files) it reduced to 37 gigabyte that was not enough, so I did this solution: (I did not need the ldf file (log file) anymore)

    (**Important) : Get a full backup of your database before the process.

    1. Run "checkpoint" on that database.

    2. Detach that database (right click on the database and chose tasks >> Detach...) {if you see an error, do the steps in the end of this text}

    3. Move MyDatabase.ldf to another folder, you can find it in your hard disk in the same folder as your database (Just in case you need it in the future for some reason such as what user did some task).

    4. Attach the database (right click on Databases and chose Attach...)

    5. On attach dialog remove the .ldf file (which shows 'file not found' comment) and click Ok. (don`t worry the ldf file will be created after the attachment process.)

    6. After that, a new log file create with a size of 504 KB!!!.

    In step 2, if you faced an error that database is used by another user, you can:

    1.run this command on master database "sp_who2" and see what process using your database.

    2.read the process number, for example it is 52 and type "kill 52", now your database is free and ready to detach.

    If the number of processes using your database is too much:

    1.Open services (type services in windows start) find SQL Server ... process and reset it (right click and chose reset).

    1. Immediately click Ok button in the detach dialog box (that showed the detach error previously).

提交回复
热议问题