Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

shrinking logfile in SQL 2008 Expand / Collapse
Author
Message
Posted Monday, February 9, 2009 1:19 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 2:47 AM
Points: 102, Visits: 343
I cannot manage to shrink my logfile and datafile, the command used before in SQL 2000 doesn't work anymore, Urgent assistance is required please, tried doing it from the Management Studio as well but file does not shrink

executed:
dbcc shrinkfile (ServerAdmin_log, truncateonly)
dbcc shrinkfile (ServerAdmin_log, 1000)
Error:
Cannot shrink log file 2 (ServerAdmin_Log) because of minimum log space required.
The other error i recieved was:Cannot shrink log file 2 (ServerAdmin_Log) because all logical log files are in use
Post #652579
Posted Monday, February 9, 2009 1:33 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, November 29, 2013 1:32 AM
Points: 1,118, Visits: 261
make sure there are no open transactions before shrinking the log, also insted of using 1000 try ,0 this will take it down to what ever space is free not just to zero bytes.

dbcc opentran (database)
go
and so on.

Terry
Post #652581
Posted Monday, February 9, 2009 1:50 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 2:47 AM
Points: 102, Visits: 343
dbcc opentran (ServerAdmin)
go
dbcc shrinkfile (ServerAdmin_log, truncateonly)
dbcc shrinkfile (ServerAdmin_log, 0)

Results:
No active open transactions.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Cannot shrink log file 2 (ServerAdmin_Log) because the logical log file located at the end of the file is in use.

I cannot shrink the logfile and datafile to any amount then what it's currently at. How is this possible
Post #652587
Posted Monday, February 9, 2009 2:15 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, February 11, 2013 2:29 PM
Points: 27, Visits: 126
There are some common reasons why a transaction log might not shrink when you use the DBCC SHRINKFILE or DBCC SHRINKDATABASE command.
Please rerfer to the following link http://support.microsoft.com/kb/q256650/


SET NOCOUNT ON

DECLARE @LogicalFileName SYSNAME,
@MaxMinutes INT,
@NewSize INT,
@Factor FLOAT

USE

--Use sp_helpfile to identify the logical file name that you want to shrink.
SET @LogicalFileName = 'databasename_Log';
--Limit on time allowed to wrap log in minutes
SET @MaxMinutes = 5;
--Ideal size of logfile in MB
SET @NewSize =100;

SET @Factor = 1.0;
DECLARE @OriginalSize INT,
@StringData VARCHAR(500)

SELECT @OriginalSize = size -- in 8K pages
FROM sysfiles
WHERE name = @LogicalFileName;

SELECT @StringData = 'Original Size of ' + db_name() + ' LOG is ' +
CONVERT(VARCHAR(30),@OriginalSize) + ' 8K pages or ' +
CONVERT(VARCHAR(30),(@OriginalSize*8/1024)) + 'MB'
FROM sysfiles
WHERE name = @LogicalFileName;

PRINT @StringData;
PRINT ''

--Drop the temporary table if it already exists
IF ( OBJECT_ID('[dbo].[DummyTrans]') IS NOT NULL )
DROP TABLE [DummyTrans]

CREATE TABLE [DummyTrans]( [DummyColumn] CHAR(8000) NOT NULL );

-- Wrap log and truncate it.
DECLARE @Counter INT,
@MaxCount INT,
@StartTime DATETIME,
@TruncLog VARCHAR(500)

-- Try an initial shrink.
DBCC SHRINKFILE (@LogicalFileName, @NewSize)

SET @TruncLog = 'BACKUP LOG [' + db_name() + '] WITH TRUNCATE_ONLY';
EXEC (@TruncLog)

-- Configure limiter
IF @OriginalSize / @Factor > 50000
SET @MaxCount = 50000
ELSE
SET @MaxCount = @OriginalSize * @Factor

-- Attempt to shrink down the log file
PRINT 'Minimum Quantity : '+CAST( @MaxCount AS VARCHAR(10) )
PRINT 'Maximum Time : '+CAST( @MaxMinutes AS VARCHAR(10) )+' minutes ('+CAST( @MaxMinutes*60 AS VARCHAR(10) )+' seconds)'
PRINT ''

SET @Counter = 0;
SET @StartTime = GETDATE();

--loop the padding code to reduce the log while
-- within time limit and
-- log has not been shrunk enough
WHILE (
(@MaxMinutes*60 > DATEDIFF(ss, @StartTime, GETDATE())) AND
(@OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)) AND
((@OriginalSize * 8 / 1024) > @NewSize)
)
BEGIN --Outer loop.

--pad out the logfile a page at a time while
-- number of pages padded does not exceed our maximum page padding limit
-- within time limit and
-- log has not been shrunk enough
WHILE (
(@Counter < @MaxCount) AND
(@MaxMinutes*60 > DATEDIFF(ss, @StartTime, GETDATE())) AND
(@OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)) AND
((@OriginalSize * 8 / 1024) > @NewSize)
)
BEGIN --Inner loop

INSERT INTO DummyTrans VALUES ('Fill Log') -- Because it is a char field it inserts 8000 bytes.
DELETE FROM DummyTrans
SELECT @Counter = @Counter + 1

--Every 1,000 cycles tell the user what is going on
IF ROUND( @Counter , -3 ) = @Counter
BEGIN
PRINT 'Padded '+LTRIM( CAST( @Counter*8 AS VARCHAR(10) ) )+'K @ '+LTRIM( CAST( DATEDIFF( ss, @StartTime, GETDATE() ) AS VARCHAR(10) ) )+' seconds';
END
END

--See if a trunc of the log shrinks it.
EXEC( @TruncLog )

END
PRINT ''

SELECT @StringData = 'Final Size of ' + db_name() + ' LOG is ' +
CONVERT(VARCHAR(30),size) + ' 8K pages or ' +
CONVERT(VARCHAR(30),(size*8/1024)) + 'MB'
FROM sysfiles
WHERE name = @LogicalFileName;

PRINT @StringData
PRINT ''

DROP TABLE DummyTrans;
PRINT '*** Perform a full database backup ***'

SET NOCOUNT OFF

Post #652596
Posted Monday, February 9, 2009 2:49 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 2:47 AM
Points: 102, Visits: 343
Result after executing your statemet

Original Size of ServerAdmin LOG is 358648 8K pages or 2801MB

Cannot shrink log file 2 (ServerAdmin_Log) because the logical log file located at the end of the file is in use.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Msg 155, Level 15, State 1, Line 1
'TRUNCATE_ONLY' is not a recognized BACKUP option.
Minimum Quantity : 50000
Maximum Time : 5 minutes (300 seconds)


Final Size of ServerAdmin LOG is 330112 8K pages or 2579MB
Post #652616
Posted Monday, February 9, 2009 2:53 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, February 11, 2011 8:31 PM
Points: 297, Visits: 277
try this backup database name with no_log ..then try to shrink the database....
Post #652619
Posted Monday, February 9, 2009 2:58 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, November 17, 2014 6:16 AM
Points: 222, Visits: 334
stop all the activity on the db, if needed kill threads.
change the recovery model to simple and then shrink it.

Worst case even then if it is not resolved, dettacch the db,move the log file to other location and then attach the mdf file in single file mode,


Sriram

Post #652623
Posted Monday, February 9, 2009 3:29 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 2:47 AM
Points: 102, Visits: 343
Aha thanx that seems to do the trick, Changed the recovery model to simple then shrunk the logfile using the shrink tool in Server Management Studio. Thanks alot for all the assistance

Grasshopper
Why do you have to change the recovery model in order to shrink the files
Post #652638
Posted Monday, February 9, 2009 3:50 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, November 17, 2014 6:16 AM
Points: 222, Visits: 334
Brother, In Simple recovery model the logs are not saved or in other words truncated when ever there is a commit. It is not desirable to do this until unless it is highly important.

As you said it has worked change it back "FULL"

Sriram


Sriram

Post #652661
Posted Monday, February 9, 2009 4:17 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 21, 2014 2:56 AM
Points: 2,603, Visits: 2,061
If your database is Production than after changing db back to Full recovery mode do not forget to take full backup.



---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Post #652679
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse