SQL Server:如何增加事务日志的大小?
如何增加事务日志的大小? 是否也可以暂时增加事务日志?
假设我有以下场景。 我的删除操作对于当前事务日志来说太大。 我不想:
- 增加事务日志(我可以检测当前大小吗?我可以知道我的操作需要多大的事务日志吗?)
- (执行我的操作)
- 备份事务日志
- 恢复事务日志的大小交易日志。
How do I increase the size of the transaction log? Is is also possible to temporarily increase the transaction log?
Let's say I have the following scenario. I have a Delete operation that's too big for the current transaction log. I wan't to:
- Increase the transaction log (can I detect the current size?, can I tell how large I need the transaction log to be for my operation?)
- (Perform my operation)
- Backup the transaction log
- Restore the size of the transaction log.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短回答:
长答案:您可以使用
ALTER DATABASE ... MODIFY FILE
来更改数据库文件的大小,包括LOG文件。 您可以查找master_files/sysfiles
(2k) 或.sys.database_files
(2k5/2k8) 以获取日志的逻辑名称。 您可以使用DBCC SHRINKFILE
来缩小文件(如果可能)。它取决于很多因素(这是新数据吗?是更新吗?是删除吗?什么恢复模型?您对 SQL 2k8 有压缩吗?等等),但通常比您预期的要大。 我估计是您将要执行的更新大小的 2.5 倍。
更新:
错过你说的是删除。 粗略估计是删除数据大小(包括所有索引)的1.5倍。
Short answer:
Long answer: you can use
ALTER DATABASE ... MODIFY FILE
to change the size of database files, including LOG files. You can look upmaster_files/sysfiles
(2k) or<dbname>.sys.database_files
(2k5/2k8) to get the logical name of the log. And you can useDBCC SHRINKFILE
to shrink a file (if possible).It depends on a lot of factors (is this new data? is it an update? is it a delete? what recovery model? Do you have compression on SQL 2k8? etc etc) but is usually bigger than you expect. I would estimate 2.5 times the size of the update you are about to perform.
Update:
Missed you say is an DELETE. A rough estimate is 1.5 times the size of the data deleted (including all indexes).
事务日志可以配置为根据需要扩展。 您将选项设置为自动增长。
但是,当事务日志变得太大(磁盘空间不足)或导致 sql server 无法使用时。
备份事务日志。 SQL 将自动截断非活动事务
当您恢复时,事务日志将减少
要配置自动增长:
The transaction log can be configured to expand as needed. You set the option to grow automatically.
However when the transaction log gets too big (running out of disk space) or making sql server unusable.
Back up transaction log. SQL will auto truncate inactive transactions
When you restore the transaction log will be reduced
To configure autogrow:
最重要的部分是场景的最后一行:“恢复事务日志的大小”。 你的意思是把日志缩小回原来的大小。
由于多种原因,这确实很危险,我们在 SQLServerPedia 的几个故事中介绍了它们:
The most important part is the last line of your scenario: "Restore the size of the transaction log." You mean shrink the log back to its original size.
This is really dangerous for a lot of reasons, and we've covered them in a couple of stories over at SQLServerPedia: