简体   繁体   English

SQL Server 日志文件大小

[英]SQL Server Log File Size

Apologies if this question was asked by someone.如果有人问这个问题,我深表歉意。 I'm not much experienced in SQL server.我在 SQL 服务器方面没有太多经验。

On our SQL server, there is 1 TB plus log file size.在我们的 SQL 服务器上,有 1 TB 加上日志文件大小。 Database is in full recovery.数据库处于完全恢复状态。 Had taken an initial full backup and set a regular backup job for a transaction log for a stop to growing log file size too much.已进行初始完整备份并为事务日志设置常规备份作业,以阻止日志文件大小增长过多。

so my question is, can I truncate my log file after taking log backup.所以我的问题是,我可以在进行日志备份后截断我的日志文件吗?

If there was abnormal event like long running transaction or huge data import, you restore the previous size with the code below:如果出现长时间运行的事务或大量数据导入等异常事件,您可以使用以下代码恢复以前的大小:

DBCC SHRINKFILE(2,TRUNCATEONLY);
ALTER DATABASE [StackOverflow] MODIFY FILE (NAME = N'StackOverflow_Log', SIZE = 256MB);

The SHRINKFILE second argument is the file_id : SHRINKFILE第二个参数是file_id

SELECT *
FROM sys.database_files;

Also, sometimes having a huge log file might be something normal.此外,有时拥有巨大的日志文件可能是正常的。 It basically depends on the activity on your database.它基本上取决于数据库上的活动。 So, 256 MB might be more or less.因此, 256 MB可能或多或少。 It will be better to set a size, which will be enough for handling your normal workload without growing.最好设置一个大小,这将足以处理您的正常工作量而不会增加。

You should also check how often you are performing backup of the log file - each 10 minute or each 1 hour.您还应该检查执行日志文件备份的频率 - 每 10 分钟或每 1 小时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM