文件日志_SQL日志文件過大問題的解決方法
YINGSOO專業(yè)提供海外云服務(wù)器,包括亞洲、歐美等全球范圍內(nèi)的服務(wù)器租用、托管業(yè)務(wù),云主機節(jié)點覆蓋全球,現(xiàn)擁有20多個節(jié)點并持續(xù)增加中,1對1客服專屬服務(wù)、瞬時響應(yīng),365*7*24h售后保障。客服熱線:400-630-3752
DECLARE @LogicalFileName sysname,
@MaxMinutes INT,
@NewSize INT
USE data_db -- 要操作的數(shù)據(jù)庫名
SELECT @LogicalFileName = 'data_db_log', -- 日志文件名
@MaxMinutes = 10, -- Limit on time allowed to wrap log.
@NewSize = 100 -- 你想設(shè)定的日志文件的大小(M)
-- Setup / initialize
DECLARE @OriginalSize int
SELECT @OriginalSize = size
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)
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, @StartTime, GETDATE()) -- time has not expired
AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)
AND (@OriginalSize * 8 /1024) > @NewSize
BEGIN -- Outer loop.
SELECT @Counter = 0
WHILE ((@Counter < @OriginalSize / 16) AND (@Counter < 50000))
BEGIN -- update
INSERT DummyTrans valueS ('Fill Log')
DELETE DummyTrans
SELECT @Counter = @Counter + 1
END
EXEC (@TruncLog)
END
SELECT '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
DROP TABLE DummyTrans
SET NOCOUNT OFF
以上代碼用T-SQL語言實現(xiàn)。
YINGSOO(www.sddonglingsh.com)提供高速穩(wěn)定的香港云主機、美國云主機等全球20個節(jié)點的云主機租用服務(wù),幫助用戶快速構(gòu)建穩(wěn)定、安全的應(yīng)用,提升運維效率,降低IT成本,香港云主機購買鏈接:http://www.sddonglingsh.com/products/cloud-hk.html,更多節(jié)點詳詢客服Lucy-微信號:YINGSOO-VIP5 / 企業(yè)QQ:3002703903
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。