Two methods of SQL Server log clearance

xiaoxiao2021-03-06  40

Two methods of SQL Server log clearance

Method In general, the shrinkage of the SQL database does not greatly reduce the size of the database. Its main role is to shrink the log size. This action should be performed regularly to prevent the database log excessively 1. Setting the database mode as simple mode: Open SQL Enterprise Manager, click Microsoft SQL Server in the Content Tablet Directory -> SQL Server Group -> Double click to open your server -> Double click to open the database directory -> Select your database name (such as Forum Database forum -> Then click Right click Select Properties -> Select Options -> Select "Simple" in the fault reduction mode, then press OK Save 2, right-click on the current database, see the contraction database in all tasks, general The default settings inside are not adjusted, the direct point is determined 3, after the shrink database is completed, it is recommended to reset your database properties to the standard mode, the operation method is the first point, because the log is often an important basis for restoring the database in some abnormalities method two SET NOCOUNT ONDECLARE @LogicalFileName sysname, @MaxMinutes INT, @NewSize INT USE tablename - name of the database to be operated SELECT @LogicalFileName = 'tablename_log', - log file name @MaxMinutes = 10, - Limit on time allowed to . wrap log @NewSize = 1 - you want to set the size of the log file (M) - Setup / initializeDECLARE @OriginalSize intSELECT @OriginalSize = size FROM sysfiles WHERE name = @LogicalFileNameSELECT '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 = @LogicalFileNam eCREATE 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 'Dbcc shrinkfile (@LogicalFileName, @newsize) Exec (@trunclog) - Wrap the log if Necessary.While @maxminutes> datediff (mi, @

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

New Post(0)