Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to reduce the log file of a large database?

how to reduce the log file of a large database?

Scheduled Pinned Locked Moved Database
databasetutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    ma amer
    wrote on last edited by
    #1

    i have a database with a large log file database and i don't know how to do to make it smaller,,, the file have a large area space what can i do???

    N A 2 Replies Last reply
    0
    • M ma amer

      i have a database with a large log file database and i don't know how to do to make it smaller,,, the file have a large area space what can i do???

      N Offline
      N Offline
      Natza Mitzi
      wrote on last edited by
      #2

      You are not telling us what type of DB you are using. Beware of erasing log files or minimizing log levels since mistakes do happen and when they do, these files are life savers especially in production.

      Natza Mitzi

      M 1 Reply Last reply
      0
      • N Natza Mitzi

        You are not telling us what type of DB you are using. Beware of erasing log files or minimizing log levels since mistakes do happen and when they do, these files are life savers especially in production.

        Natza Mitzi

        M Offline
        M Offline
        ma amer
        wrote on last edited by
        #3

        thanks... :) sorry,,, SQL SERVER database would u help me ???

        modified on Tuesday, March 17, 2009 7:06 PM

        S 1 Reply Last reply
        0
        • M ma amer

          thanks... :) sorry,,, SQL SERVER database would u help me ???

          modified on Tuesday, March 17, 2009 7:06 PM

          S Offline
          S Offline
          scottgp
          wrote on last edited by
          #4

          Do you know what recovery model you are using (simple vs full)? Are you backing up the database? What version of SQL Server is it? Scott

          1 Reply Last reply
          0
          • M ma amer

            i have a database with a large log file database and i don't know how to do to make it smaller,,, the file have a large area space what can i do???

            A Offline
            A Offline
            Aman786Singh
            wrote on last edited by
            #5

            run this if you are working in sql 2005 server. but for this u need to make your database offline first and then run this code. --INF: How to Shrink the SQL Server 7.0 Transaction Log -- SQL7 http://support.microsoft.com/support/kb/articles/q256/6/50.asp?id=256650&SD -- SQL7 http://www.support.microsoft.com/kb/256650 -- SQL2000 http://support.microsoft.com/kb/272318/en-us -- SQL2005 http://support.microsoft.com/kb/907511/en-us -- select db_name() -- select * from sysfiles -- THIS SCRIPT IS NOT INTENDED FOR SCHEDULED USAGE !! READ BOL and the urls !! SET NOCOUNT ON DECLARE @LogicalFileName sysname, @MaxMinutes INT, @NewSize INT -- *** MAKE SURE TO CHANGE THE NEXT 3 LINES WITH YOUR CRITERIA. *** SELECT @LogicalFileName = 'Test_Log', -- Use sp_helpfile to identify the logical file name that you want to shrink. @MaxMinutes = 10, -- Limit on time allowed to wrap log. @NewSize = 305 -- in MB -- Setup / initialize DECLARE @OriginalSize int SELECT @OriginalSize = size -- in 8K pages FROM sysfiles WHERE name = @LogicalFileName SELECT '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 CREATE TABLE DummyTrans (DummyColumn char (8000) not null) -- Wrap log and truncate it. DECLARE @Counter INT, @StartTime DATETIME, @TruncLog VARCHAR(255) SELECT @StartTime = GETDATE(), @TruncLog = 'BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY' -- Try an initial shrink. DBCC SHRINKFILE (@LogicalFileName, @NewSize) EXEC (@TruncLog) -- Wrap the log if necessary. WHILE @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName) -- the log has not shrunk AND (@OriginalSize * 8 /1024) > @NewSize -- The value passed in for new size is smaller than the current size. BEGIN -- Outer loop. SELECT @Counter = 0 WHILE ((@Counter < @OriginalSize / 16) AND (@Counter < 50000)) BEGIN -- update INSERT DummyTrans VALUES ('Fill Log') -- Because it is a char field it inserts 8000 bytes. DELETE DummyTrans SELECT @Counter = @Counter + 1 END -- update EXEC (@TruncLog) -- See if a trunc of the log shrinks it. END -- outer loop SELECT 'Fina

            M 1 Reply Last reply
            0
            • A Aman786Singh

              run this if you are working in sql 2005 server. but for this u need to make your database offline first and then run this code. --INF: How to Shrink the SQL Server 7.0 Transaction Log -- SQL7 http://support.microsoft.com/support/kb/articles/q256/6/50.asp?id=256650&SD -- SQL7 http://www.support.microsoft.com/kb/256650 -- SQL2000 http://support.microsoft.com/kb/272318/en-us -- SQL2005 http://support.microsoft.com/kb/907511/en-us -- select db_name() -- select * from sysfiles -- THIS SCRIPT IS NOT INTENDED FOR SCHEDULED USAGE !! READ BOL and the urls !! SET NOCOUNT ON DECLARE @LogicalFileName sysname, @MaxMinutes INT, @NewSize INT -- *** MAKE SURE TO CHANGE THE NEXT 3 LINES WITH YOUR CRITERIA. *** SELECT @LogicalFileName = 'Test_Log', -- Use sp_helpfile to identify the logical file name that you want to shrink. @MaxMinutes = 10, -- Limit on time allowed to wrap log. @NewSize = 305 -- in MB -- Setup / initialize DECLARE @OriginalSize int SELECT @OriginalSize = size -- in 8K pages FROM sysfiles WHERE name = @LogicalFileName SELECT '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 CREATE TABLE DummyTrans (DummyColumn char (8000) not null) -- Wrap log and truncate it. DECLARE @Counter INT, @StartTime DATETIME, @TruncLog VARCHAR(255) SELECT @StartTime = GETDATE(), @TruncLog = 'BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY' -- Try an initial shrink. DBCC SHRINKFILE (@LogicalFileName, @NewSize) EXEC (@TruncLog) -- Wrap the log if necessary. WHILE @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName) -- the log has not shrunk AND (@OriginalSize * 8 /1024) > @NewSize -- The value passed in for new size is smaller than the current size. BEGIN -- Outer loop. SELECT @Counter = 0 WHILE ((@Counter < @OriginalSize / 16) AND (@Counter < 50000)) BEGIN -- update INSERT DummyTrans VALUES ('Fill Log') -- Because it is a char field it inserts 8000 bytes. DELETE DummyTrans SELECT @Counter = @Counter + 1 END -- update EXEC (@TruncLog) -- See if a trunc of the log shrinks it. END -- outer loop SELECT 'Fina

              M Offline
              M Offline
              ma amer
              wrote on last edited by
              #6

              thanks for all,,, :) i'am sorry the sql server recovery model is full and its version is sql server 2000 i have to reduce the size of this log file when i deleted it the database don't work, it is suspect and didn't work

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups