|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 6:49 AM
Points: 90,
Visits: 266
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, September 20, 2012 9:27 PM
Points: 1,118,
Visits: 258
|
|
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
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 6:49 AM
Points: 90,
Visits: 266
|
|
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
|
|
|
|
|
SSC 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
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 6:49 AM
Points: 90,
Visits: 266
|
|
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
|
|
|
|
|
SSC 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....
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Monday, April 29, 2013 12:19 AM
Points: 219,
Visits: 326
|
|
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
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 6:49 AM
Points: 90,
Visits: 266
|
|
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
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Monday, April 29, 2013 12:19 AM
Points: 219,
Visits: 326
|
|
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
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 3:39 AM
Points: 1,768,
Visits: 1,312
|
|
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."
|
|
|
|