r/SQLServer • u/Deep-Egg-6167 • Apr 22 '26
Question SQL newbie - transaction logs and backup?
Hello,
It has been ages since I set up a MS SQL server. I have an MS SQL 2022 server. It has a dedicated drive for the logs. The logs keep on growing. I remember how to shrink them but I forgot to stop them from growing.
I think it was something to do with the backup would auto clean them?
I could use a lot of spoon feeding on this. Thanks!!
15
Upvotes
•
u/AutoModerator Apr 22 '26
After your question has been solved /u/Deep-Egg-6167, please reply to the helpful user's comment with the phrase "Solution verified".
This will not only award a point to the contributor for their assistance but also update the post's flair to "Solved".
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
14
u/ImprovementGuilty392 Apr 22 '26
Search for Ola Hallengren and use his scripts to setup SQL agent job to take log backups every minute.
Or
If you don't need point-in-time recovery, you can change the recovery model to simple. This can help prevent the logs from growing in size.
8
u/Ill_Drag6021 1 Apr 22 '26 edited Apr 22 '26
If the database is in Full recovery mode, the transaction logs won't truncate until a transaction log backup is taken. Really this needs a job creating and running on a schedule.
If database is in simple recovery, the logs clear down once the transaction completes. If the logs have grown due to usage, it is likely your drive isn't large enough to cope with the transaction volume or maintance running.
3
u/alinroc 4 Apr 22 '26
Your database(s) is/are using the full recovery model, which allows you to do point in time restores from backup. But the transaction log will not "clear" until you back it up - this is what causes it to keep growing.
A large transaction left open can also cause the log to grow even if you are taking log backups, but from your description it sounds like this isn't the case.
You need to:
You need the backups scheduled. Common frequencies are:
Exact scheduling will depend upon your business requirements for RTO and RPO, as well as how long it takes for a restore in your environment.
If you install Ola Hallengren's Maintenance Solution (https://ola.hallengren.com), the installer can set up the jobs for you. You can use the "pure SQL" installation that Ola has there, or if you like PowerShell,
Install-DbaMaintenanceSolutionfromdbatools.If you do not need point in time recovery, you can switch to the SIMPLE recovery model, schedule your FULL (and optionally DIFF) backups, and then shrink your transaction log to an appropriate size.
1
u/kagato87 Apr 23 '26
You shouldn't need to shrink them, they should not be growing.
Check your backups. Your backups need to be actually connecting to the sql engine and taking log backups (usually capturing those to a virtual device to your backup appliance).
Anything else doesn't work well.
If your backups are disk, block, or file based, they won't move that checkpoint and it will grow.
You could switch to simple recovery. It's usually fine, especially if whatever writes to that database goes silent during the backup window. But there are some advantages to have your backup correctly configured.
Namely, in full recovery mode with proper sql aware log backups, it's nigh impossible to corrupt the backup (as long as you don't break the chain...).
Second, if it's a bigger database with smaller daily incremental daily changes, log based backups are stupendously fast, and get faster the more often they run. I do log backups hourly - the databases are abiut 200gb each, a full backup to local disk is 20 minutes, to the appliance is closer to 40. Hourly transaction logs to the appliance rarely get to double digit seconds.
1
u/7amitsingh7 Apr 23 '26
SQL Server transaction logs keep growing because they only get reused when SQL Server can safely clear inactive log records, which depends on the database recovery model in FULL recovery mode you must regularly take transaction log backups(you can take help from this article to understand backups clearly) to “free” space inside the log, while in SIMPLE recovery mode SQL Server automatically reuses log space after checkpoints; if you’re in FULL recovery and not doing log backups, the log will grow indefinitely even if you do full backups, so the fix is either to set up frequent transaction log backups (which is the proper production approach and allows point-in-time recovery) or switch to SIMPLE recovery if you don’t need that level of recovery, and shrinking the log is not a real solution because it only reduces file size temporarily and the problem will return unless the backup/truncation process is corrected.
0
u/NoNotice5674 Apr 23 '26
You can either set the databases to SIMPLE recovery mode and shrink the log files or backup your transaction log on a regular basis to avoid it growing in size.
Create a database maintenance plan under the Management folder and the wizard will walk you through setting up regular database backups and cleanups and all of that great stuff.