Truncate and shrink log files in SQL Server (2024)

This article describes the difference between shrinking and truncating the transaction log in Microsoft® SQL Server®. It outlines the different use scenarios and walks you through how to perform these tasks.

If a database is a simple recovery model, the system truncates the transaction log automatically after every transaction. For databases with a full or bulk-logged recovery model, the system truncates the transaction log only after a successful transaction log backup.

A full database backup does not truncate the log. If you don't take regular transaction log backups, the log file continues to grow until it runs out of space. While truncating the log makes the space available for use again, it does not decrease the transaction log file size. To reduce the size of the transaction log file, you need to shrink the log file.

Truncate the transaction log

Use the following steps to truncate the transaction log file in SQL Server Management Studio (SQL Server 2008 and later). Keep in mind that following these steps might result in data loss. You should not need to manually truncate the log because regular log backups should automatically perform this task.

Note: You need the sysadmin fixed server role or the db_owner fixed database role to truncate the 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.

  6. When the process completes, switch the recovery model back to Full or Bulk-Logged and take a full database backup.

Understand shrinking the log

If you need to recover disk space from the transaction log file, consider shrinking the log file. Shrinking recovers space by moving data from the end of the file to unoccupied space at the front of the file. After the process creates enough space at the end of the file, it can be deallocated and returned to the file system. Shrinking logs helps after you perform an action that creates a large number of logs. You can only shrink the log if there is free space on the log file.

Shrink the transaction log

Use the following steps to truncate the transaction log file:

Note: You need the sysadmin fixed server role or the db_owner fixed database role to shrink the log.

  1. Right-click the database and select Tasks -> Shrink -> Files.

  2. Change the type to Log.

  3. Under Shrink action, select Release unused space and click OK.

Related Articles:

SQL Server database recovery models

Updated 9 months ago

Truncate and shrink log files in SQL Server (2024)
Top Articles
Cisco ACI: Streamlining Network Operations
33 Profitable Reseller Business Ideas | ZenBusiness Inc.
11 beste sites voor Word-labelsjablonen (2024) [GRATIS]
Genesis Parsippany
Craigslist Vans
Couchtuner The Office
Workday Latech Edu
25X11X10 Atv Tires Tractor Supply
Wells Fargo Careers Log In
Bucks County Job Requisitions
How Far Is Chattanooga From Here
Barstool Sports Gif
Mivf Mdcalc
No Strings Attached 123Movies
Elbasha Ganash Corporation · 2521 31st Ave, Apt B21, Astoria, NY 11106
Apne Tv Co Com
Aberration Surface Entrances
Swgoh Turn Meter Reduction Teams
라이키 유출
SF bay area cars & trucks "chevrolet 50" - craigslist
Forum Phun Extra
Airrack hiring Associate Producer in Los Angeles, CA | LinkedIn
Pjs Obits
Kaitlyn Katsaros Forum
Melendez Imports Menu
Certain Red Dye Nyt Crossword
Deshuesadero El Pulpo
The Banshees Of Inisherin Showtimes Near Broadway Metro
Paris Immobilier - craigslist
Medline Industries, LP hiring Warehouse Operator - Salt Lake City in Salt Lake City, UT | LinkedIn
What Is Opm1 Treas 310 Deposit
Used 2 Seater Go Karts
Grays Anatomy Wiki
Gr86 Forums
Kstate Qualtrics
Kelsey Mcewen Photos
CVS Near Me | Somersworth, NH
Powerspec G512
Collier Urgent Care Park Shore
7543460065
Stafford Rotoworld
Rochester Ny Missed Connections
Blackstone Launchpad Ucf
South Bend Tribune Online
Barstool Sports Gif
Craigslist St Helens
The Blackening Showtimes Near Ncg Cinema - Grand Blanc Trillium
Google Flights Missoula
M Life Insider
Runelite Ground Markers
Electronics coupons, offers & promotions | The Los Angeles Times
Room For Easels And Canvas Crossword Clue
Latest Posts
Article information

Author: Nathanael Baumbach

Last Updated:

Views: 6545

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Nathanael Baumbach

Birthday: 1998-12-02

Address: Apt. 829 751 Glover View, West Orlando, IN 22436

Phone: +901025288581

Job: Internal IT Coordinator

Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.