I have inherited a 10 GB database with an 80 GB log [only 3% in use according to DBCC SQLPERF(logspace)]. It seems safe to assume the extreme log growth was due to problems from long before I was hired.
The primary has a log shipping backup job that runs every 15 minutes. The primary has copy and restore jobs that run every 15 minutes.
When I attempt to shrink the log, I get "Cannot shrink log file 2 (DatabaseName_log) because the logical log file located at the end of the file is in use." I have retried this several times 15 minutes apart and even days apart, but always get the same result.
DBCC LOGINFO shows 784 VLFs, with only the first 245 and the last on with a status of 2. p_WhoIsActive shows that the longest open transaction has been running for less than 2 hours (long transactions are not unusual here due to a third-party Microsoft Access app with ODBC driver issues).
How can I successfully shrink this log (without creating an outage for users)?
Thanks, Mark
SELECT d.name, d.log_reuse_wait_desc FROM sys.databases d
say about the DB in question? The VLF at the end marked as status 2 is the problem. The transactions in that VLF need to be backed up, and transferred to the secondary, then the VLF marked as status 0 before you can shrink the file.