如何查询SQL Server数据库恢复需要多长时间?
我正在尝试编写一个查询来告诉我在 SQL Server 2008 上恢复(完整或日志)花费了多少时间。
我可以运行此查询来找出备份花费了多少时间:
select database_name,
[uncompressed_size] = backup_size/1024/1024,
[compressed_size] = compressed_backup_size/1024/1024,
backup_start_date,
backup_finish_date,
datediff(s,backup_start_date,backup_finish_date) as [TimeTaken(s)],
from msdb..backupset b
where type = 'L' -- for log backups
order by b.backup_start_date desc
此查询将告诉我 恢复了什么内容,但现在花费了多少时间:
select * from msdb..restorehistory
restorehistory
有一个列 backup_set_id
,它将链接到 msdb..backupset
,但它保存的是备份的开始和结束日期,而不是恢复的开始和结束日期。
知道在哪里查询恢复的开始和结束时间吗?
Im trying to write a query that will tell me how much time a restore (full or log) has taken on SQL server 2008.
I can run this query to find out how much time the backup took:
select database_name,
[uncompressed_size] = backup_size/1024/1024,
[compressed_size] = compressed_backup_size/1024/1024,
backup_start_date,
backup_finish_date,
datediff(s,backup_start_date,backup_finish_date) as [TimeTaken(s)],
from msdb..backupset b
where type = 'L' -- for log backups
order by b.backup_start_date desc
This query will tell me what is restored but now how much time it took:
select * from msdb..restorehistory
restorehistory
has a column backup_set_id
which will link to msdb..backupset
, but that hold the start and end date for the backup not the restore.
Any idea where to query the start and end time for restores?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要查找 RESTORE DATABASE 时间,我发现您可以使用以下查询:
缺点是,您会注意到,至少在我的测试服务器上,
EndTime
始终为 NULL。因此,我提出了第二个查询来尝试确定结束时间。首先,我很抱歉这非常丑陋并且疯狂地嵌套。
下面的查询假设如下:
我确信有人可能会采用我所做的并改进它,但这似乎适用于我的测试环境:
编辑
我对查询做了一些更改,因为我的测试数据库之一used 区分大小写,并且丢失了一些记录。我还注意到从磁盘恢复时
DatabaseID
为空,所以我现在也处理这个问题:To find the RESTORE DATABASE time, I have found that you can use this query:
The downside is, you'll notice that, at least on my test server, the
EndTime
is always NULL.So, I came up with a second query to try and determine the end time. First of all, I apologize that this is pretty ugly and nested like crazy.
The query below assumes the following:
RESTORE DATABASE
and the maximum transaction associated with that record.I'm sure someone can probably take what I've done and refine it, but this appears to work on my test environment:
EDIT
I made some changes to the query, since one of the test databases I used is case-sensitive and it was losing some records. I also noticed when restoring from disk that the
DatabaseID
is null, so I'm handling that now as well:让它成为一份工作。然后将其作为作业运行。然后检查查看作业历史记录。然后查看持续时间列。
Make it a Job. Then run it as the Job. Then check the View Job History. Then look at the duration column.
当它运行时,您可以检查类似 dmv 的内容。
或者您可以使用一些神奇的巫术并解释下表函数中的事务日志,但是我认识的唯一能够理解此日志中任何信息的人是 Paul Randal。
我知道他有时会检查服务器故障,但不知道他是否想知道 StackOverflow。
select * from fn_dblog(NULL,NULL)
希望这有帮助。
如果您设法使用它并找到解决方案,请告诉我们。
祝你好运!
While it is running you can check something like this dmv.
Or you can use some magic voodoo and interpret the transaction log in the following table function, however the only person I know to understand any info in this log is Paul Randal.
I Know he sometimes checks Server Fault, but don't know if he wonders StackOverflow.
select * from fn_dblog(NULL,NULL)
Hope this helps.
If you manage to use this and find a solution please tell us.
Good Luck!
我们可以从SQL中获取数据库恢复的开始时间,我们可以通过事件查看器找到结束时间,进入windows日志-应用程序-过滤日志源MSSQLSERVER,它会有数据库恢复时的条目。
We can get the start time of the database restore from SQL, we can find out end time from event viewer by going to windows logs - application - filter the log source MSSQLSERVER, it will have the entry when the database restoration.