×


Manage Transaction Log File during Data Load - Do it Now

Are you trying to Manage Transaction Log File during Data Load? 

We can help you.


Sometimes in the process of migrating SQL server database, we may end up in situations where the log file grows extensively during data load. And this can also lead to failure of import.

When the transaction log files grow exceptionally and we have to manage log files to make them within the size limit.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to manage transaction logs.


How to manage Transaction Log File during Data Load ?

To manage the transaction log,

We can do this with the following steps:


1. Add Log File to a Database

We can add log files to a database using T-SQL statements and using GUI in SQL Server Management Studio to manage transaction log files during data load.

This way we can manage if the transaction log file is growing faster.


2. Using T-SQL Statement

Open a new query window and run the following T-SQL statement to add a log file TY1_Log3.ldf to database TY1 on F drive:

ALTER DATABASE [TY1]
ADD LOG FILE (NAME = 'TY1_Log3', FILENAME = 'F:\TY1_Log3.ldf', SIZE = 20080 MB, FILEGROWTH = 5024 MB)
GO

This T-SQL code will get us details like sizing and growth of log.


Once we execute the above T-SQL statement, our log file TY1_Log3.ldf will be added on F drive to the database TY1.

We must note that when we add the log file to a drive it must have enough space.

If we add a log file to the data file drive, then we might face IO pressure because both data and log files will be on the same drive. So avoid keeping data and log files on the same drive.


How to use GUI in SQL Server Management Studio ?

We can also manage transaction log files using GUI in SQL server. 

This can be done using the following steps:

1. First, launch SQL Server Management Studio and connect to the instance of the SQL Server Database Engine. Expand Databases folder.

2. Then right-click the database in which we have to add the log file and then click Properties.

3. After that, select the Files page.

4. For adding a transaction log file, we need to click Add button.

5. Then select the file type as log. Specify the initial size of the file. Set Autogrowth column as per our requirement.

6. Now we can specify the path for the file location along with the physical log file name.

7. Finally, click on the OK button to create this add this log file to the database.


Now log file will be added to our database on identified drive name.


[Need assistance in performing related SQL Queries? We can help you. ]


Conclusion

This article covers how to manage transaction log files in SQL Server for our customers. A transaction log is a file – integral part of every SQL Server database. It contains log records produced during the logging process in a SQL Server database.

The transaction log is the most important component of a SQL Server database when it comes to the disaster recovery – however, it must be uncorrupted.

The only way to truncate the log, so the space can be reused, is to perform a SQL transaction log backup. Therefore the most common reason for a transaction log file to have grown extremely large is because the database is in the FULL recovery model and LOG backups haven't been taken for a long time.


How do I stop a transaction log from filling up?

1. To keep the log from filling up again, schedule log backups frequently. 

2. When the recovery mode for a database is set to Full, then a transaction log backup job must be created in addition to backing up the database itself.


To fix a transaction log for a database is full:

1. Backing up the log.

2. Freeing disk space so that the log can automatically grow.

3. Moving the log file to a disk drive with sufficient space.

4. Increasing the size of a log file.

5. Adding a log file on a different disk.