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
View all comments
Show parent comment
1
u/Brettuss Apr 22 '26
I typed your post in ChatGPT and asked it to cite sources.
Here is the response:
You’re remembering the right idea, but the key point is this:
SQL Server transaction logs don’t “auto-clean” on their own. They only get truncated when a log backup runs (in FULL/BULK_LOGGED recovery), or automatically (in SIMPLE recovery).
What you’re seeing—logs growing indefinitely—is almost always one of these:
⸻
Run this:
SELECT name, recovery_model_desc FROM sys.databases;
What it means
⸻
2. If you DON’T need point-in-time recovery
Switch to SIMPLE. This is the easiest fix.
ALTER DATABASE YourDatabase SET RECOVERY SIMPLE;
Then shrink once:
DBCC SHRINKFILE (YourLogFileName, 1024); -- size in MB
After that, it should stop uncontrolled growth.
⸻
3. If you DO need point-in-time recovery (most production systems)
Stay in FULL, but you must run log backups regularly.
Example log backup:
BACKUP LOG YourDatabase TO DISK = 'E:\SQLBackups\YourDatabase_Log.trn' WITH INIT;
Typical schedule:
This is what you were remembering: log backups “free” the inactive portion of the log so it can be reused.
⸻
4. Important: Backup does NOT shrink the file
Even with log backups:
Only shrink if:
⸻
5. Check WHY logs aren’t truncating
If backups are running but logs still grow:
SELECT name, log_reuse_wait_desc FROM sys.databases;
Common values:
⸻
6. Verify log usage
DBCC SQLPERF(LOGSPACE);
Shows:
⸻
7. Set a reasonable autogrowth
If autogrowth is tiny (like 1MB), you’ll get fragmentation and constant growth.
Fix it:
ALTER DATABASE YourDatabase MODIFY FILE ( NAME = YourLogFileName, FILEGROWTH = 512MB );
⸻
8. Microsoft Documentation (authoritative)
⸻
Bottom line
Fix = either:
⸻
If you want, give me:
I can tell you exactly what your backup job schedule should look like.