I was wondering if there is a way (MUST be) to instruct SQL server to compact a chosen database's files. I have a batch that runs every night who generate a huge amount to log lines that I get rid of with a backup log xxx with truncate_only, but still the logfile is several GB big afterwards with a lotsa empty space... I wanna get a clean small file everyday =)
Its not ideal to shrink the Transaction log every day, rather define a set of size by testing the activity on the database.
During that batch overnight take before and after sizes for Tlog and set the higher level.
Also maintain regular backups of Tlogs which will reduce the size of logical file and helps to fillup the Tlog quickly. If RECOVERY MODEL Is set to SIMPLE then ensure full database backups are carried in regular intervals.
DBCC SHRINKFILE (logical file name,Target_size)
Target_size is how much free size is left over after you shrink
if you leave this off, you will get the default.
you may have to switch the VLogs internally before you can shrink to a size that you desire...
all of his should be done after a tlog backup.
look up "Shrinking the Transaction Log" AND DBCC Shrinkfile in [BOL]