How do I truncate a transaction log in SQL Server?

How do I truncate a transaction log in SQL Server?

Truncate the transaction log

  1. Right-click the database and select Properties -> Options.
  2. Set the recovery model to Simple and exit the menu.
  3. Right-click the database again and select Tasks -> Shrink -> Files.
  4. Change the type to Log .
  5. Under Shrink action, select Reorganize pages before releasing unused space and click OK.

How does SQL log truncation work?

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.

How do I purge SQL log files?

In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Expand Databases, right-click the database from which to delete the file, and then click Properties. Select the Files page. In the Database files grid, select the file to delete and then click Remove.

What is the function of a transaction log?

A transaction log is used to record the fact that a transaction is set to occur as well as the information needed by the database server to recover the data back to a consistent state in event of a sever failure while it is writing information to disk.

When to truncate SQL Server transaction log file?

If no Transaction Log backup is taken from the database, the Transaction Log file will grow continuously, without truncation, until it runs out of free space. The SQL Server Transaction Log backup can be taken only from the database when the recovery model of that database is Full or Bulk-Logged.

Is the truncation process automatic in SQL Server?

The truncation process is automatic. In this mode, you can roll back your DB only to the database full backup creation time; Full recovery model — the transaction log won’t be cleared until a backup of the transaction log is completed.

When to take a SQL Server transaction log backup?

The SQL Server Transaction Log backup can be taken only from the database when the recovery model of that database is Full or Bulk-Logged. The recovery model of the database can be checked form the Options tab of the Database Properties window, as below:

Why are transaction logs overflowing in SQL Server?

Back up the transaction log for the database to free up some log space. In most cases, SQL Server administrators encounter transaction logs overflow in SQL if a regular backup of the transaction log is not performed, and the recovery model is BULK LOGGED or FULL.