Заметки сисадмина » Modify sql transaction log file size – increase or decrease

Заметки сисадмина о интересных вещах из мира IT, инструкции и рецензии. Настраиваем Компьютеры/Сервера/1С/SIP-телефонию в Москве

Modify sql transaction log file size – increase or decrease

2020-11-13 · Posted in SQL

Modifying the sql transaction log file size is required on certain occasions. For example, a large INSERT job requiring to preallocate the transaction log file size for performance gains.Read How to find sql transactions with large logs  for techniques on finding queries generating large transaction logs

It is not uncommon for the largest time portion of  a large transaction to be the sql transaction log file size growth. If the DBA can predict the sql transaction log size , then adjusting the size before the INSERT can save significant time. Read more on  SQL Server – Preallocate SQL Transaction Logs for large queries – Initial Size

The ideal time to modify the transaction log file size is when there are no active transactions. Both increase log file size and decrease log file size are managed through the ALTER DATABASE .. MODIFY FILE syntax.

There are some added preliminary steps for the decrease size.

Let’s walk through an example of creating a database based on default settings , increasing the transaction log file size and then decreasing the transaction log file size

Create a database . This syntaxt will use the model database settings

Increase the sql transaction log file physical size

Decrease the sql transaction log file physical size

if you attempt a ALTER DATABASE with MODIFY FILE you’ll get this error

Msg 5039, Level 16, State 1, Line 1

MODIFY FILE failed. Specified size is less than or equal to current size.

To decrease the transaction log file size log , truncation must occur to free disk space. To reduce the log file physical size shrink to eliminate incative virtual log files

Alter DB modify log file for all DBs

Is it possible to create a script which changes log file size to let’s say 100MB for all DBs in all servers instead of running the above command by logging into each server? We have about 200 servers and close to 3000 DBs.

Leave a Reply