Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server: How do I increase the size of the transaction log?

How do I increase the size of the transaction log? Is is also possible to temporarily increase the transaction log?

Let's say I have the following scenario. I have a Delete operation that's too big for the current transaction log. I wan't to:

  • Increase the transaction log (can I detect the current size?, can I tell how large I need the transaction log to be for my operation?)
  • (Perform my operation)
  • Backup the transaction log
  • Restore the size of the transaction log.
like image 754
Niels Bosma Avatar asked Jun 18 '09 07:06

Niels Bosma


People also ask

How big should a transaction log be SQL Server?

Although there is no one optimal value for Transaction Log File initial size and auto-growth that fits all situations, but setting the initial size of the SQL Server Transaction Log file to 20-30% of the database data file size and the auto-growth to a large amount, above 1024MB, based on your database growth plan can ...

What is the size of transaction log file?

If you set the maximum file size to unlimited, the maximum size for the transaction log will be set to the limiting amount of 2 TB.

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

Short answer:

  • SQL 2k5/2k8 How to: Increase the Size of a Database (SQL Server Management Studio) (applies to log also), How to: Shrink a Database (SQL Server Management Studio)
  • SQL 2K How to increase the size of a database (Enterprise Manager), How to shrink a database (Enterprise Manager)

Long answer: you can use ALTER DATABASE ... MODIFY FILE to change the size of database files, including LOG files. You can look up master_files/sysfiles (2k) or <dbname>.sys.database_files (2k5/2k8) to get the logical name of the log. And you can use DBCC SHRINKFILE to shrink a file (if possible).

can I tell how large I need the transaction log to be for my operation?

It depends on a lot of factors (is this new data? is it an update? is it a delete? what recovery model? Do you have compression on SQL 2k8? etc etc) but is usually bigger than you expect. I would estimate 2.5 times the size of the update you are about to perform.

Update:

Missed you say is an DELETE. A rough estimate is 1.5 times the size of the data deleted (including all indexes).

like image 141
Remus Rusanu Avatar answered Oct 07 '22 09:10

Remus Rusanu