DBAtlas · 数据库运维图谱

监控日志传送状态与延迟

SQL ServerAlways On 与高可用

命令

-- Summary (on the primary, secondary or monitor server):
EXEC master.sys.sp_help_log_shipping_monitor;

-- PRIMARY: when the last log backup was taken:
SELECT p.primary_server, p.primary_database,
       p.last_backup_date, p.last_backup_file,
       DATEDIFF(MINUTE, p.last_backup_date, GETDATE()) AS backup_age_min,
       p.backup_threshold                              AS threshold_min
FROM   msdb.dbo.log_shipping_monitor_primary p;

-- SECONDARY: copy and restore latency:
SELECT s.secondary_server, s.secondary_database, s.primary_server,
       s.last_copied_date, s.last_copied_file,
       s.last_restored_date, s.last_restored_file,
       s.last_restored_latency                           AS restore_latency_min,
       DATEDIFF(MINUTE, s.last_restored_date, GETDATE()) AS since_last_restore_min,
       s.restore_threshold                               AS threshold_min
FROM   msdb.dbo.log_shipping_monitor_secondary s;

-- Errors in the last 24 hours:
SELECT e.database_name, e.agent_type, e.log_time, e.message
FROM   msdb.dbo.log_shipping_monitor_error_detail e
WHERE  e.log_time >= DATEADD(HOUR, -24, GETDATE())
ORDER BY e.log_time DESC;

-- Secondary DB mode (RESTORING = NORECOVERY, is_in_standby = STANDBY):
SELECT name, state_desc, is_in_standby FROM sys.databases WHERE name = N'Musteri';

作用

显示主服务器上最后一次日志备份的时长、辅助服务器上最后复制/还原的文件和还原延迟及其阈值,以及过去 24 小时内备份/复制/还原作业的错误。

适用场景

日志传送警报作业触发(错误 14420/14421)、DR 演练之前,或报告辅助服务器落后多少时。

注意

监视表只包含服务器能看到的一侧:主表在主服务器/监视服务器上填充,辅助表在辅助服务器/监视服务器上填充。手动(非日志传送)日志备份会断开链,还原作业会持续失败;临时日志备份请使用 COPY_ONLY。在 STANDBY 模式下,每次还原前会断开用户连接。只读查询;安全。

在 DBAtlas 中打开 →

相关内容