SQL Server 中的 LDF 文件是什么? [英] What is the LDF file in SQL Server?

查看:63
本文介绍了SQL Server 中的 LDF 文件是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server 中的 LDF 文件是什么?它的目的是什么?

What is the LDF file in SQL Server? what is its purpose?

我可以安全地删除它吗?或减小其大小,因为有时它比数据库文件 mdf 大 10 倍.

can I safely delete it? or reduce its size because sometimes it's 10x larger than the database file mdf.

推荐答案

LDF 保存事务日志.如果您正确设置了备份 - 它会很小.它增长 - 您有一个非常常见的问题,即将数据库恢复模式设置为 FULL,然后忘记备份事务日志(LDF 文件).让我解释一下如何修复它.

LDF holds the transaction log. If you set your backups correctly - it will be small. It it grows - you have a very common problem of setting database recovery mode to FULL and then forgetting to backup the transaction log (LDF file). Let me explain how to fix it.

  1. 如果您的企业能够承受在备份之间丢失少量数据,只需将数据库恢复模式设置为 SIMPLE,然后忘记 LDF - 它会很小.这是大多数情况下推荐的解决方案.
  2. 如果您必须能够恢复到准确的时间点 - 使用完全恢复模式.在这种情况下,您必须定期进行事务日志备份.最简单的方法是使用像 SqlBackupAndFTP 这样的工具(披露 - 我是一名开发人员).日志文件此时将被截断,并且不会超出特定限制.
  1. If your business can afford to lose a little data between backups, just set the database recovery mode to SIMPLE, then forget about LDF - it will be small. This is the recommended solution for most of the cases.
  2. If you have to be able to restore to the exact point in time - use FULL recovery mode. In this case you have to take regular Transaction Log backups. The simplest way to do it is to use a tool like SqlBackupAndFTP (disclosure - I am a developer). The log file will be truncated at this time and would not grow beyond certain limits.

有些人会建议使用 SHRINKFILE 来修剪您的日志.请注意,这仅作为例外是可以的.如果你经常这样做,它就违背了完整恢复模型的目的:首先你会遇到保存日志中每一个更改的麻烦,然后你只是转储它.将恢复模式改为简单.

Some would suggest to use SHRINKFILE to trim you log. Note that this is OK only as an exception. If you do it regularly, it defeats the purpose of FULL recovery model: first you go into trouble of saving every single change in the log, then you just dump it. Set recovery mode to SIMPLE instead.

这篇关于SQL Server 中的 LDF 文件是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆