SQL Server 2008 收縮日誌

若是SQL SERVER 日誌過大,好比,達到了幾十個G,想一次性收縮的,直接執行下面命令便可:數據庫

USE DATABASENAME;ui

GO日誌

– Truncate the log by changing the database recovery model to SIMPLE.事務

ALTER DATABASE DATABASENAMEfile

SET RECOVERY SIMPLE;model

GO數據

– Shrink the truncated log file to 1 MB.tab

DBCC SHRINKFILE (DATABASENAME_Log, 1);備份

GOco

– Reset the database recovery model.

ALTER DATABASE DATABASENAME

SET RECOVERY FULL;

GO

正常來說,應該是先執行一次備份事務日誌,而後在執行數據庫收縮命令,就能正常的收縮日誌大小了。

一、定時執行備份事務日誌,天天凌晨1點執行

BACKUP LOG [uiyi] TO DISK = N’F:\DB_Backup\Log\uiyi\uiyi_backup_2013_06_21_145209_5008471.trn’ WITH NOFORMAT, NOINIT, NAME = N’uiyi_backup_2013_06_21_145209_4948467′, SKIP, REWIND, NOUNLOAD, STATS = 10

二、收縮日誌,天天凌晨2點執行

use uiyi

go

DBCC SHRINKFILE (uiyi1224_Log, 50);

三、備份全量數據庫,天天凌晨3點執行

BACKUP DATABASE [uiyi] TO DISK = N’F:\DB_Backup\All\uiyi\uiyi_backup_2013_06_21_145557_3298781.bak’ WITH NOFORMAT, NOINIT, NAME = N’uiyi_backup_2013_06_21_145557_3268780′, SKIP, REWIND, NOUNLOAD, STATS = 10

GO

相關文章
相關標籤/搜索