Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-09-29 : 07:57:55
|
| Jason writes "I have a 9 gb transaction log. I backup nightly, my other logs on this server are just fine (3 other databases all managed with same maintenance plan). Shrink has no effect.I ran into this problem a while back on a different server, I was able to find a script which was referred to as "Walking the log" which basically filled up the log with junk entries which forced the problem row to a point where BACKUP LOG WITH TRUNCATE_ONLY could do its job.Do you know where I could find such a script, or any other way to fix this log file?SQL 7 sp 4NT 4 sp 6a" |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-09-29 : 11:07:57
|
| Have you tried DBCC SHRINKFILE or DBCC SHRINKDATABASE? Also, what is your database recovery model set to?Tara |
 |
|
|
jharwood
Starting Member
41 Posts |
Posted - 2003-09-29 : 12:41:08
|
| I had this from the old swynk.com scripts. It's made for 7.0. Sorry about the formatting...create proc sp_force_shrink_log---------------------------------------------------------------------------------- Purpose: Shrink transaction log of the current database in SQL Server 7.0.-- Author: Andrew Zanevsky, AZ Databases, Inc., 12/25/1999, v5 - 08/18/2000-- zanevsky@azdatabases.com-------------------------------------------------------------------------------- @target_percent tinyint = 0, @target_size_MB int = 10, @max_iterations int = 1000, @backup_log_opt nvarchar(1000) = 'with truncate_only'asset nocount ondeclare @db sysname, @last_row int, @log_size decimal(15,2), @unused1 decimal(15,2), @unused decimal(15,2), @shrinkable decimal(15,2), @iteration int, @file_max int, @file int, @fileid varchar(5)select @db = db_name(), @iteration = 0create table #loginfo ( id int identity, FileId int, FileSize numeric(22,0), StartOffset numeric(22,0), FSeqNo int, Status int, Parity smallint, CreateTime datetime )create unique clustered index loginfo_FSeqNo on #loginfo ( FSeqNo, StartOffset )create table #logfiles ( id int identity(1,1), fileid varchar(5) not null )insert #logfiles ( fileid ) select convert( varchar, fileid ) from sysfiles where status & 0x40 = 0x40 select @file_max = @@rowcountif object_id( 'table_to_force_shrink_log' ) is null exec( 'create table table_to_force_shrink_log ( x nchar(3000) not null )' )insert #loginfo ( FileId, FileSize, StartOffset, FSeqNo, Status, Parity, CreateTime ) exec ( 'dbcc loginfo' )select @last_row = @@rowcountselect @log_size = sum( FileSize ) / 1048576.00, @unused = sum( case when Status = 0 then FileSize else 0 end ) / 1048576.00, @shrinkable = sum( case when id < @last_row - 1 and Status = 0 then FileSize else 0 end ) / 1048576.00from #loginfoselect @unused1 = @unused -- save for laterselect 'iteration' = @iteration, 'log size, MB' = @log_size, 'unused log, MB' = @unused, 'shrinkable log, MB' = @shrinkable, 'shrinkable %' = convert( decimal(6,2), @shrinkable * 100 / @log_size )while @shrinkable * 100 / @log_size > @target_percent and @shrinkable > @target_size_MB and @iteration < @max_iterations begin select @iteration = @iteration + 1 -- this is just a precaution exec( 'insert table_to_force_shrink_log select name from sysobjects delete table_to_force_shrink_log') select @file = 0 while @file < @file_max begin select @file = @file + 1 select @fileid = fileid from #logfiles where id = @file exec( 'dbcc shrinkfile( ' + @fileid + ' )' ) end exec( 'backup log [' + @db + '] ' + @backup_log_opt ) truncate table #loginfo insert #loginfo ( FileId, FileSize, StartOffset, FSeqNo, Status, Parity, CreateTime ) exec ( 'dbcc loginfo' ) select @last_row = @@rowcount select @log_size = sum( FileSize ) / 1048576.00, @unused = sum( case when Status = 0 then FileSize else 0 end ) / 1048576.00, @shrinkable = sum( case when id < @last_row - 1 and Status = 0 then FileSize else 0 end ) / 1048576.00 from #loginfo select 'iteration' = @iteration, 'log size, MB' = @log_size, 'unused log, MB' = @unused, 'shrinkable log, MB' = @shrinkable, 'shrinkable %' = convert( decimal(6,2), @shrinkable * 100 / @log_size )endif @unused1 < @unused select 'After ' + convert( varchar, @iteration ) + ' iterations the unused portion of the log has grown from ' + convert( varchar, @unused1 ) + ' MB to ' + convert( varchar, @unused ) + ' MB.'union allselect 'Since the remaining unused portion is larger than 10 MB,' where @unused > 10union allselect 'you may try running this procedure again with a higher number of iterations.' where @unused > 10union allselect 'Sometimes the log would not shrink to a size smaller than several Megabytes.' where @unused <= 10elseselect 'It took ' + convert( varchar, @iteration ) + ' iterations to shrink the unused portion of the log from ' + convert( varchar, @unused1 ) + ' MB to ' + convert( varchar, @unused ) + ' MB'exec( 'drop table table_to_force_shrink_log' ) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-09-29 : 12:47:32
|
| To format the code, put code tags around it, like this:[ c o d e ]SELECT name...[ / c o d e ]Just remove the spaces from the above and it'll format the code for you. The code tags will not be displayed in the post. Your code just needs to be formatted BEFORE you copy it into the post.Tara |
 |
|
|
|
|
|
|
|