TSQL:如何获取事务日志的大小?
如何获取事务日志的当前大小?如何获得大小限制?
我想对此进行监控,以便确定需要多久备份一次事务日志。
当我执行大型操作时,事务日志通常会出现问题。
How do I get the current size of the transaction log? How do I get the size limit?
I'd like to monitor this so I can determine how often I need to backup the transaction log.
I usually have a problem with the transaction log when I perform large operations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基于 SQL Server 2005,请尝试以下操作
将 YourDB 更改为您的数据库名称
对于所有数据库大小的总体情况,请尝试 DBCC SQLPERF
这应该适用于 SQL 2000/2005/2008
Based on SQL Server 2005, try this
Change YourDB to your database name
For an overall of all database sizes try DBCC SQLPERF
This should work in SQL 2000/2005/2008
如果您想实时监视它,请在执行这些大型操作时尝试性能监视器(perfmon)。
Perfmon 可用于许多不同的场景。
请访问 Technet 了解更多信息。
If you want to monitor it in real time, try Performance Monitor (perfmon) while you are doing those large operations.
Perfmon can be used in many different scenarios.
Find out more from Technet.
从 SQL Server 2012 开始,还有另一个 DMV(动态管理视图)可用 - sys.dm_db_log_space_usage。它的优点是返回事务日志大小而不是事务日志文件大小(可能包括未使用的空间)。这将随着空间的消耗而改变,而不仅仅是当文件增长时。
仅此视图就支持在日志文件增长点之前停止。
它可以与 sys.database_files 视图及其
max_size
列,以获得“已消耗的最大大小百分比”的更精细值' 比 sys.database_files 单独查看。From SQL Server 2012, there is another DMV (Dynamic Management View) available - sys.dm_db_log_space_usage. It has the advantage of returning the transaction log size as opposed to the transaction log file size (which might include unused space). This will change as space is consumed and not just when the file grows.
This view alone would support stopping prior to the point at which the log file grows.
It could be used in combination with the sys.database_files view and its
max_size
column to get a more granular value for 'percentage of maximum size that has already been consumed' than would be possible with the sys.database_files view alone.