Original: SQL Server log file large shrinkage method (measured and useful)
These two commands are executed consecutively, with less time and more apparent (multiple runs) until the effect is reached
-- truncate BACKUP LOG to DISK = ' NUL ' -- Shrinkage DBCC Shrinkfile ('cloudmonitor_log')
You can use regular regular backup logs (such as once an hour) to prevent the log file from growing indefinitely.
The large shrinkage of SQL Server log files is not easy, as mentioned in the article:
Due to the first day log, tail log, and space reuse, when log truncation occurs after the backup logs, it is marked as reusable, but only the free space at the end of the file can be shrunk. This results in a 98% of the available space in the log file, but no movement is made to shrink. Skip "Active Log" as much as possible by backup + shrink continuous operation
"Shrink file" has tried, and will not achieve the effect:
1. Free unused space
2. Reorganize the page before releasing unused space
In response to this issue, there are other practices on the web that can be shrunk by modifying the "Simple recovery" mode, but this method does not apply to AlwaysOn of course, Microsoft Official also to this issue to explain: "In some cases, until the next log truncation, to shrink the log." "Official document: Factors that shrink the transaction log may delay log truncation