"Collection" SQL script for shrinking log files

zhaozj2021-02-16  70

* This article is extracted by Microsoft News Group. A very useful script. * /

A few days ago, I also encountered the problem of excessive log files. The actual size of the database is 600m. The actual size of the log file is 33m, but the log file takes up the space of 2.8G !!! Try a variety of ways, Shirnk Database, Truncate log file, There is no way to narrow the file. Anyway, this should be a bug of SQL Server.

Later, I find the following code, you can narrow the log file to the size you want. Put the code COPY to the query analyzer, then modify the three parameters (the database name, log file name, and the size of the target log file), run (I have used it many times) ----- Set NoCount Ondeclare @LogicalFileName Sysname, @ Maxminutes Int, @ Newsize Int

Use Marias - Database name to be operated SELECT @LogicalFileName = 'Marias_log', - log file name @MaxMinutes = 10, - limit on time allowed to wrap log. @ Newsize = 100 - You want to set the log file you want to set Size (m)

- Setup / initializeDECLARE @OriginalSize intSELECT @OriginalSize = sizeFROM sysfilesWHERE name = @LogicalFileNameSELECT 'Original Size of' db_name () 'LOG is' CONVERT (VARCHAR (30), @ OriginalSize) '8K pages or' CONVERT (VARCHAR (30), (@ OriginalSize * 8/1024)) 'MB'From sysfileswhere name = @LogicalFileNamecreate Table DummyTrans (DummyColumn char (8000) Not null

Declare @counter int, @ starttime datetime, @ trunclog varchar (255) select @starttime = getdate (), @ Trunclog = 'backup log' db_name () 'with truncate_only'

转载请注明原文地址:https://www.9cbs.com/read-16663.html

New Post(0)