0% found this document useful (0 votes)
5 views3 pages

Log File Shrink

Uploaded by

Rahul Chaurasia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Log File Shrink

Uploaded by

Rahul Chaurasia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Tested in Tieto by ME

If you are trying to shrink Log File and its not shrinking then use below method to shrink :-

1. See for any active transaction

Query: - DBCC OPENTRAN ('YourDatabaseName');

2. See if log is being used or waiting for anything: -

Query: - SELECT name, log_reuse_wait_desc FROM sys.databases WHERE name =


'YourDatabaseName';

3. See what log is doing: -

Query: - DBCC LOGINFO ('YourDatabaseName');

Soln: - Active VLFs will have a status of 2, and the log can only be shrunk if inactive VLFs are available
(status 0).

4. Take Full backup with compression.

5. Then take 2-3 log Backup (.trn) and then try to shrink. After that I was able to shrink.

Used by me in BIRLASOFT Project :- In Birlasoft, we use to have multiple log files for a database, so we
use below method :-

 uery to check Log Spce :-

DBCC SQLPERF (logspace)


-----------------------------------------------------------------------------------

Query to shrink when we have multiple Log Files :-

Use dbname;
Go
Alter database dbname set recovery simple;
Go
DBCC SHRINKFILE (LOGFILE name, 1,truncateonly) ;
Go
Alter Database dbname set recovery full;
Go

Example:---
1. First run sp_helpfile against Database for which you need to shrink logfile.
Here we have to run for “tempdb”.

2. Then, You have to run shrink query mentioned above.

You have to change db name and logfile name and then run the query.
logfile name = name (see ina bove image)

Ex:- If we have to run query for “tempdev2 (logfile name)” query will be as :-

Use tempdb;
Go

Alter database tempdb set recovery simple;

Go

DBCC SHRINKFILE (tempdev2, 1,truncateonly) ;

Go

Alter Database tempdb set recovery full;

Go

 Query to check Log Spce :-


DBCC SQLPERF (logspace)

You might also like