Can I use a shrink to reduce log size? Even if users are using websites?
No, users will be blocked while the shrink operation is occurring. Plus, you'll have to do it over and over again unless you address the root cause of the growth.
For a really thorough treatment of why the log file keeps growing, see Why Does the Transaction Log Keep Growing or Run Out of Space?
When your websites are always running, you're producing more log records than the size of the log file in a single day, resulting in the file growth.
You have a few options:
- Leave the database in the
SIMPLE recovery model
With this approach, you don't take log backups at all. You take the full backup once per day, as you always do. If there were a crash or some other need to recover from a backup, you could lose up to one day of data.
ALTER DATABASE [DatiMachinaWeb]
SET RECOVERY SIMPLE;
- Take log backups more often
You can take as many log backups as you like between full backups. Taking a log backup will free up space in the log (referred to as "truncation") and prevent the log file from growing. This is really the best, and most common, option for dealing with log file growth.
- Permanently increase the log file size to accommodate the once-per-day log backups
The default log file size in SQL Server 2019 is 8 MB. If your system does more than 8 MB worth of transactions in a day, that log file will grow (by default, it will grow by 64 MB).
Assuming the amount of transactions your system does is somewhat consistent from day to day, the growth of the log file will eventually normalize. After the first growth event, the log will be 72 MB - if you don't do more than 72 MB of transactions in a day, the log file should stay that size.
- Lower likelihood: investigate long-running transactions
It's possible that your websites are causing the log file to not be truncated when they are in this "always running" mode. Maybe they start a transaction on startup, and don't commit or rollback until they shut down.
If the log file continues to grow, even with frequent log backups or a sufficiently large log file, you can run this query to see what is preventing log file truncation:
SELECT
d.[name],
d.log_reuse_wait,
d.log_reuse_wait_desc
FROM sys.databases d
WHERE
d.[name] = 'DatiMachinaWeb';
FULLandSIMPLErecovery and shrinking the log file? The normal practice is to keep the database inFULLand backup the transaction log periodically between database backups. This will facilitate point-in-time recovery and manage log file size by removing committed transactions from the log. – Dan Guzman Jul 02 '20 at 10:47