SQL 2012 database log file too big, no disk space

Posted on 2016-08-17
Last Modified: 2016-08-26
Dear all,

I have MS SQL 2012 server and the transaction log file has grown too big and the partition where the log file resides is out of space. Unable to run queries due to this issue. Any help on what best to do in this scenario would be appreciated.

Question by:ghco
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 41759095
Are you performing transaction log backups? If you weren't then that explains the transaction log being growing without any kind of truncation.
So to solve your issue you'll need to perform ASAP a transaction log backup and then schedule regular transaction log backups.
LVL 25

Expert Comment

by:Lee Savidge
ID: 41759099
First of all why has this happened? Is the recovery model set to full or simple? If set to full, you MUST back up the database AND transaction log as part of your maintenance schedule.

If you don't your log file will simply increase until it runs out of disk space. This is perhaps the single most common problem that people face with a database.

So, what can you do? Well, if the disk is full, the application is not working, so try and do a database back up and then a transaction log backup to a different partition. Then when you've backed the transaction log up, you will need to shrink it.

Try that, then come back to let us know if it has worked. There are things you can do if it doesn't work so don't worry.

Author Comment

ID: 41759144
Thanks for the quick respond, the recovery model is set to simple. Will try what you suggested and let you know the outcome.

As an alternative can the log file be moved to another partition while the database is active?
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

LVL 50

Expert Comment

by:Vitor Montalvão
ID: 41759148
If the database is set to Simple then you can't perform transaction log backups. I'm wondering what can made the transaction log growing too much in a Simple Recovery model database. How big is the database and the transaction log file?

For moving a transaction log location you'll need to detach the database, copy the transaction log file to the new location and re attach the database.

Author Comment

ID: 41759159
The database grew from 3GB to 40GB and the log file is 45GB. Apparently there was a massive entry to database table that wasn't necessary which made it grew, have tried deleting those entries but script wouldn't run because of the disk space issue.
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 41759166
A massive data task can really justifies the grow but then it would empty the transaction log when the task is done. Mind that emptying the tlog is not the same that shrinking it so it may be your case. Did you try to Shrink the transaction log to see if you can recall any free space? If not then it means that the transaction it still active (still running or waiting for a commit/rollback).
LVL 27

Expert Comment

ID: 41759429
Use this script to shrink the log file:
USE [YourDatabase] 


DBCC SHRINKFILE(N'YourDatabase_log', 1) 

Open in new window

where YourDatabase_log should be the logica file name of the transaction log file.
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41759485
Yes, use commands, not the gui, to shrink the log file.

USE [db_name]

That will shrink it to 4GB.  I wouldn't shrink too small, because when the log is forced to grow again, that will be very bad for performance.

Also, check to be sure that nothing is preventing the log from shrinking/being reused, with this command:


Author Comment

ID: 41762063
Found an MSDN link that shows how to shrink the database/log file from the SQL Management Studio so this worked for us. Thanks for all the help.
LVL 27

Accepted Solution

Zberteoc earned 500 total points
ID: 41762577
In that article under "Using Transact-SQL" section is exactly what I posted as a solution at: 41759429

Expert Comment

by:Jason clark
ID: 41763385
By querying the sys.databases catalog view you can see information describing the reason your log file may be waiting on truncate/reuse. see here to know other reasons for that:

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question