By J.D.

2019-03-13 18:09:58 8 Comments

If I size my log files to evenly split the entire drive they reside on, leaving no extra space available, will log backups still be able to occur successfully? I have several databases, with one log file per database.

Is it good practice to not leave any space on the drive available, i.e. allocate it all to the log files? (The drive is dedicated to the log files in this case, data and the OS live on their own partitions.)


@Max Vernon 2019-03-13 18:20:57

There is no technical problem for SQL Server if the drive where the log file exists has no free space, assuming the log itself doesn't run out of available, unused, VLF entries.

If the log runs out of available space, you'll not be able to commit any transactions until you resolve the problem. If the entire drive is consumed by the log file, the only action you can take is to add a log file on a different drive to the database. If you proactively manage your log file, and never run out of log space, there is no technical prohibition from doing what you're contemplating.

Having said that, I wouldn't recommend sizing your log file to consume all available drive space:

  1. Windows will complain about the disk being out of space, which can be annoying.
  2. If you do run out of log space, and you almost certainly will at some point, the database will not be accessible until you add a new log file.
  3. How much does disk space cost? Almost nothing in comparison with the price of SQL Server Enterprise Edition licensing, and the potential cost to the business from down-time. Ask yourself why you wouldn't leave a little space free on the drive. Please don't take this to mean I'm endorsing using the wrong data types such as using a bigint instead of an int, or even a smallint. Unused disk space is cheap, but space used inside a database should be considered premium cost for the reasons succinctly outlined by @SolomonRutzky here.

In a comment, you mentioned that you see no difference between a log growing to fill the disk, and the disk already being filled with a mostly empty log which subsequently gets filled. The supposition is correct, both events will result in the server returning the following error:

Msg 9002, Level 17, State 2, Line 22
The transaction log for database '<database_name>' is full due to 'LOG_BACKUP'.

However, if you have a SAN, you could thin-provision the drive with a maximum size of, say, 10TB. Create the log file with the estimated "correct" initial size, say 1GB, with growth set to 1GB (or whatever makes sense). Then you won't be using more SAN disk space than you need, but you'll have room to grow the log file without needing to involve the SAN administrator. Win-win.

In a previous version of my answer, I stated the following incorrect information:

Adding a log file when you're already out of log space can be impossible since the mere fact of adding a log file modifies the primary data file, which necessitates writing to the log. It's kind of a chicken-and-egg thing.

After some pretty extensive testing, I am able to successfully add a new log file after the existing log file runs out of space. I wrote a blog post showing how this works at The actions required for adding a new log file consist of:

  1. Physically creating the new file on disk
  2. Writing new VLF structures to the file
  3. Updating the existing log file - there must be enough space preallocated in the existing log file for just this purpose, that cannot be used for anything else.
  4. Updating the primary mdf to reflect the newly created log file.

The above was validated on SQL Server 2008 R2, and SQL Server 2016.

@Paul White 2019-03-13 23:49:32

Comments are not for extended discussion; this conversation has been moved to chat.

@Aaron Bertrand 2019-03-13 18:56:25

Well log backups don't change the size of the log file, and the only reason you'd need space on that drive is if you were backing up the log there (which is the same kind of bad idea as putting your house key and the backup on the same key ring). But a slightly different question, do you expect none of your log files to ever grow? Leaving a bit of space at least gives you some canary time where you can deal with a log file that is growing atypically. With no space leftover, as soon as the log file needs to grow, you're down.

@J.D. 2019-03-13 20:31:53

The only reasoning I had behind leaving the extra space for the log backups is because I know in some types of backup or copy operations (outside of SQL, perhaps I've seen it at the OS level in Windows) roughly the same amount of space of the data being copied needs to be available to perform the copy operation. I wasn't sure if there was any similar methodology in how log backups work.

@Aaron Bertrand 2019-03-13 20:32:32

@J.D. That is how online index rebuilds work, but it's not how log backups work.

@J.D. 2019-03-13 20:33:04

Cool, I learned something new about index rebuilds now too. Thanks! :)

Related Questions

Sponsored Content

1 Answered Questions

0 Answered Questions

2 Answered Questions

[SOLVED] SQL Server 2016 out of disk space

3 Answered Questions

[SOLVED] Truncation of transaction logs

1 Answered Questions

[SOLVED] Database reporting more space reserved than total size

  • 2017-05-26 15:34:01
  • Philip C
  • 570 View
  • 2 Score
  • 1 Answer
  • Tags:   sql-server

1 Answered Questions

3 Answered Questions

1 Answered Questions

[SOLVED] Help with Cybernetics SAN Configuration

Sponsored Content