We have a DB which is part of ALWAYS ON. We want to clear the transaction logs for that DB because that is just a production server where we replicate data from one of our other production server 4 times a day.
As we do snapshot replication of 4 GB data every time, the transaction logs are increasing day by day.
Due to limited space we thought of clearing logs everyday so that we don't hit the space issues on the.
I tried a piece of code which was working fine for a DB which is not part of ALWAYS ON.
But when I tried the code on the actual DB it did not work at all and the logs remained there.
USE AdventureWorks;
GO
EXEC sp_addumpdevice 'disk', 'AdventureWorks_backup', N'E:\Backup\AdventureWorks.bak';
Go
USE AdventureWorks;
GO
BACKUP DATABASE AdventureWorks
TO AdventureWorks_backup
WITH FORMAT,
MEDIANAME = 'AdventureWorks_backup',
MEDIADESCRIPTION = N'E:\Backup\AdventureWorks.bak',
NAME = 'AdventureWorks_backup';
GO
USE AdventureWorks;
GO
BACKUP LOG AdventureWorks
TO AdventureWorks_backup;
Go
USE AdventureWorks;
GO
CHECKPOINT
GO
USE AdventureWorks;
GO
DBCC SHRINKFILE (AdventureWorks_log,1)
GO
USE AdventureWorks;
GO
EXEC sp_dropdevice 'AdventureWorks_backup','DELFILE'
Go
In the above code I created a back up device then took back up of DB and tried to shrink the log file. But it was of no help on DB part of always on.