Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I shrink the transaction log on MS SQL 2000 databases?

I have several databases where the transaction log (.LDF) is many times larger than the database file (.MDF).

What can I do to automatically shrink these or keep them from getting so large?

like image 932
Ed Haber Avatar asked Oct 02 '08 15:10

Ed Haber


People also ask

How do I reduce the size of SQL transaction log?

To shrink a data or log file. In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Expand Databases and then right-click the database that you want to shrink. Point to Tasks, point to Shrink, and then select Files.

How do I reduce the size of my log file?

To reduce the physical size of a physical log file, you must shrink the log file. This is useful when you know that a transaction log file contains unused space. You can shrink a log file only while the database is online, and at least one virtual log file (VLF) is free.

Why is my SQL transaction log so big?

Large database transactions, such as importing large amounts of data, can lead to a large transaction log file. Transaction log backups not happening fast enough causes the SQL log file to become huge. SQL log files also enlarge due to incomplete replication or availability group synchronization.


1 Answers

That should do the job

use master
go
dump transaction <YourDBName> with no_log
go
use <YourDBName>
go
DBCC SHRINKFILE (<YourDBNameLogFileName>, 100) -- where 100 is the size you may want to shrink it to in MB, change it to your needs
go
-- then you can call to check that all went fine
dbcc checkdb(<YourDBName>)

A word of warning

You would only really use it on a test/development database where you do not need a proper backup strategy as dumping the log will result in losing transactions history. In live systems you should use solution sugested by Cade Roux

like image 80
kristof Avatar answered Oct 04 '22 21:10

kristof