To resolve the same I go around multiliple ways will explain few workaround here.
1.If database is not setup for Logshipping,Replication,Mirroring and CDC.
1. set the database into simple recovery mode
2. Set the database back to full recovery mode.
3. Run the shrinkfile command.
DBCC SHRINKFILE (2,1)
DBCC SHRINKFILE (2)
DBCC SHRINKFILE (2,truncate_only)
(Mirosoft do not recommend to use truncate statement in production)
2.In case the database is setup for Replication (any topology) and transaction log file is growing tremendously and soon will be full. Transaction Log file can’t be shrinked as there are transaction which are not marked as replicated in the transaction log file.
If transaction log is full and transaction written on the log file are not marked as replicated the logreader agent will keep trying to scan the log and mark the transaction as replicated but it will not succeed as there is no space to write transaction in the transaction (Mark the transaction as replicated).As the transaction are not marked as replicated DBA’s cant shrink the Log file.
To resolve the issue we can execute the below steps.
1. Lets say the trasaction log file is on drive D:\ of size 200 GB.
2. The transaction log file has grown by size 200 GB.
3. Create a new log file to some other drive.Let’s say on drive F:\ at the publisher database.
ALTER DATABASE [xzcvxz] ADD LOG FILE ( NAME = N’xyz_log’, FILENAME = N’F:\xyz_01.ldf’ , SIZE = 1024KB , FILEGROWTH = 10%)
4. As new log file is added to the database, SQL Server will start using it.the new transaction will be written to the newly added transaction log files.The Log reader agent will start scaning the old log file and will mark the transaction as distributed once sp_repcmd will replicate the commands or transaction to the distributor database.
5. Alter the Database in simple recovery mode.
ALTER DATABASE [xzcvxz] SET RECOVERY SIMPLE WITH NO_WAIT
6. Alter the Database again in full recovery mode.
ALTER DATABASE [xzcvxz] SET RECOVERY FULL WITH NO_WAIT
7. Now Shrink the Log file.
DBCC SHRINKFILE (2)