TSQL:如何获取事务日志的大小?

发布于 2024-08-14 21:53:13 字数 96 浏览 6 评论 0原文

如何获取事务日志的当前大小?如何获得大小限制?

我想对此进行监控,以便确定需要多久备份一次事务日志。

当我执行大型操作时,事务日志通常会出现问题。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜还是长夜 2024-08-21 21:53:13

基于 SQL Server 2005,请尝试以下操作

SELECT (size * 8)/1024.0 AS size_in_mb,
  CASE WHEN max_size = -1 THEN 9999999   -- Unlimited growth, so handle this how you want
   ELSE (max_size * 8) / 1024.0
        END AS max_size_in_mb
FROM <YourDB>.sys.database_files
WHERE data_space_id = 0   -- Log file

YourDB 更改为您的数据库名称

对于所有数据库大小的总体情况,请尝试 DBCC SQLPERF

DBCC SQLPERF (LOGSPACE)

这应该适用于 SQL 2000/2005/2008

Based on SQL Server 2005, try this

SELECT (size * 8)/1024.0 AS size_in_mb,
  CASE WHEN max_size = -1 THEN 9999999   -- Unlimited growth, so handle this how you want
   ELSE (max_size * 8) / 1024.0
        END AS max_size_in_mb
FROM <YourDB>.sys.database_files
WHERE data_space_id = 0   -- Log file

Change YourDB to your database name

For an overall of all database sizes try DBCC SQLPERF

DBCC SQLPERF (LOGSPACE)

This should work in SQL 2000/2005/2008

谁许谁一生繁华 2024-08-21 21:53:13

如果您想实时监视它,请在执行这些大型操作时尝试性能监视器(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.

¢好甜 2024-08-21 21:53:13

从 SQL Server 2012 开始,还有另一个 DMV(动态管理视图)可用 - sys.dm_db_log_space_usage。它的优点是返回事务日志大小而不是事务日志文件大小(可能包括未使用的空间)。这将随着空间的消耗而改变,而不仅仅是当文件增长时。

select
    used_log_space_in_percent  
from
    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.

select
    used_log_space_in_percent  
from
    sys.dm_db_log_space_usage;  

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文