SQL Server 2008 收缩日志

如果SQL SERVER 日志过大,比如,达到了几十个G,想一次性收缩的,直接执行下面命令即可:

USE DATABASENAME;

GO

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

ALTER DATABASE DATABASENAME

SET RECOVERY SIMPLE;

GO

– Shrink the truncated log file to 1 MB.

DBCC SHRINKFILE (DATABASENAME_Log, 1);

GO

– Reset the database recovery model.

ALTER DATABASE DATABASENAME

SET RECOVERY FULL;

GO

正常来讲,应该是先执行一次备份事务日志,然后在执行数据库收缩命令,就能正常的收缩日志大小了。

1、定时执行备份事务日志,每天凌晨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、收缩日志,每天凌晨2点执行

use uiyi

go

DBCC SHRINKFILE (uiyi1224_Log, 50);

3、备份全量数据库,每天凌晨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

你可能感兴趣的:(SQL Server 2008)