Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1553
  • Last Modified:

How do I properly remove then recreate a SQL Log file that has gotten too large

LDF File for my SQL DB has approached the point of filling the disk it is on. What is the proper way to shrink it substantially OR remove the recreate it.

Best,
D Summers
0
dsummers801
Asked:
dsummers801
1 Solution
 
OtanaCommented:
If you want to remove and recreate it, right-click on the database in Enterprise Manager, All Tasks, detach database. Rename the LDF file, and the re-attach the database (right-click on databses, all tasks, attach database). You'll get a message saying LDF file can not be found, new one will be created. If attach worked, you can delete the old LDF file.
0
 
Martin-SmithCommented:
The link above involves database downtime. To just clear the log you can set the database recovery model to simple then use the "shrink files" option. And reset the recovery model to full. This could completely mess up your backups though!
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
Kevin3NFCommented:
Back it up.  Then use the GUI to shrink it.  Simplest solution with no downtime, no changes to the database.
0
 
PaultheBrokerCommented:
I had this problem on my server - the underlying cause is the recoveryoptions that you have set.  You probably have it set so that it increments the log until backup, whereby the log would get truncated automatically, but I'm guessing you are not backing up the database, so the log file is just getting larger and larger...one solution is to create a Maintenance Plan (right click the DB -> All Tasks... in Enterprise Manager to create a backup plan.

Alternatively, along the lines that Martin suggests, change the Recovery Model to SIMPLE to eliminate the transaction log altogether ... though only good for datbases you don't care too much about !! :)

BOL entry: "When a database is created, it has the same recovery model as the model database. To alter the default recovery model, use ALTER DATABASE to change the recovery model of the model database. You set the recovery model with the RECOVERY clause of the ALTER DATABASE statement"
0
 
PaultheBrokerCommented:
So what I'm saying is that if you have a backup schedule, then the log file should automatically truncate itself, so you shouldn't need to worry about this, and if you don't have a backup schedule, then you probably don't need the log file anyway (if your system goes down, you are f***d anyway).

And I think just running a backup on the database should clear out the log file, so that is the only thing you need do....what am I missing guys???
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now