User Tools

Site Tools


public:5353_sql_transaction_log_not_smaller_after_transaction_log_backup

FAQ: SQL transaction log file size is not reduced / shrunken after a Transaction Log backup (in ODBC backup mode)?

Article ID: 5353
Reviewed: 11/09/2018

Product Version:
Ahsay Software: 7.11.0.0 or above
OS: All platforms

Description

SQL transaction log (.ldf) file size is not reduced / shrunken after a Transaction Log backup (in ODBC backup mode)?

Note:
This article only applies to MS SQL Server backup set with ODBC backup mode.

Contents

To understand why is the physical size of a transaction log (.ldf) file not reduced / shrunken after a Transaction Log backup (e.g. log truncation), you must first understand the difference between transaction log truncation and shrinking a SQL transaction log file.



A transaction log file (.ldf) of a database records all transactions and the database modifications made by each transaction.  When a Transaction Log backup (in ODBC backup mode) is performed, which triggers a log truncation operation, inactive portion of the the transaction log file are marked as re-usable (e.g. logical space within the transaction log file are cleared to be re-used).

This does not reduce / shrink the physical file size of the allocated log file on the operating system.

Microsoft's defination of transaction log truncation (https://docs.microsoft.com/en-us/sql/relational-databases/logs/the-transaction-log-sql-server?view=sql-server-2017)

Log truncation frees space in the log file for reuse by the transaction log. You must regularly truncate your transaction log to keep it from filling the alotted space.

Log truncation deletes inactive virtual log files (VLFs) from the logical transaction log of a SQL Server database, freeing space in the logical log for reuse by the physical transaction log. If a transaction log is never truncated, it will eventually fill all the disk space allocated to physical log files.
...

Note:
Log truncation does not reduce the size of the physical log file. To reduce the physical size of a physical log file, you must shrink the log file.
Shrinking a SQL transaction log file on the other hand (e.g. Shrink File operation), is used to reduce physical size of a physical log file.



According to Microsoft (https://docs.microsoft.com/en-us/sql/relational-databases/databases/shrink-a-file?view=sql-server-2017):

Shrinking data files recovers space by moving pages of data from the end of the file to unoccupied space closer to the front of the file. When enough free space is created at the end of the file, data pages at end of the file can deallocated and returned to the file system.
The Shrink File operation must be performed manually (no backup type will trigger a shrink operation) to reduce the physical size of a log file.

Now, with the above information in mind, to maintain the size of the transaction log file from getting out of control, perform regular Transaction Log backup (in ODBC mode).

Note:
More frequent log backups have the added advantage of increasing the frequency of log truncation, which helps maintain the log file at a manageable / smaller size.

To reduce the size of the log file if it had already grown out of control:

  1. Perform a Full database backup (in ODBC mode).


  2. Perform a Transaction Log backup (in ODBC mode).


  3. Reduce the transaction log file size physically by using the Shrink File option. For instruction, refer to the following document from Microsoft:

    https://docs.microsoft.com/en-us/sql/relational-databases/databases/shrink-a-file?view=sql-server-2017

    Note:
    You should only perform a Shrink File operation on the transaction log file as last resort (e.g. running out of disk space).

Keywords

sql, log, transaction, ldf, mdf, small, smaller, reduce, shrank, shrunk, shrunken, shrinking

public/5353_sql_transaction_log_not_smaller_after_transaction_log_backup.txt · Last modified: 2018/09/12 11:43 by edward.chan