my problem is really simply: shrink log file does not work. When I execute the maintenance plan (Database full backup and shrink database log) the execution terminate without problems or errors but the log file is used at the same percentage.
The Database is in AlwaysOn High Availability group. The group have 1 primary server (called BO1), 2 secondary servers (called BO2 e MI1) and I use SQL Server 2014.
After executed the backup I used the command
DBCC SQLPERF(LOGSPACE);
I did a check my log database (Database called DM_AUT). This is the result: Log Size (MB) 10689.3 and Log Space Used (%) 90.90916.
These is the script that I used for the full backup:
DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('DM_AUT'))
IF (@preferredReplica = 1)
BEGIN
BACKUP DATABASE [DM_AUT] TO DISK = N'K:\xxx\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\DM_AUT.bak' WITH COPY_ONLY, NOFORMAT, INIT, NAME = N'DM_AUT_backup_2017_02_24_125045_4829954', SKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 10
END
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'DM_AUT' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'DM_AUT' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''DM_AUT'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'K:\xxx\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\DM_AUT.bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
After the backup I executed the shrink command:
USE DM_AUT
BACKUP LOG BISYSTEM TO DISK='NUL:'
DBCC SHRINKFILE (DM_AUT_log,50)
At the end of these maintenance activities I checked the database log and the result is the same: Log Space Used (%) 90.90916.
I have other databases in this AlwaysOn group but the backup and shrink log file works fine (and are used the same scripts).
These are the database configurations:
I would like to understand how to fix the shrink log task.
Thanks to all.