Different ways to monitor Log Shipping for SQL Server databases
Log shipping has been an option for creating a failover server for SQL Server for quite some time. In this tip, we look at different ways that you can monitor the status of your log shipped databases.
Log Shipping is a basic SQL Server high-availability technology that is part of SQL Server. It is an automated backup/restore process that allows you to create another copy of your database for failover or reporting purposes.
You can use the below items to investigate if there are any issues with your databases that are setup for Log Shipping. We will cover each of these items and how they can be used.
- SQL Server Error Log
- SSMS Built In Report
- System Stored Procedures
- Query the MSDB database
- Application/System EventViewer Log
SQL Server Error Log
Check the SQL Server error log for error messages related to log shipping such as database backup and restore failures using these commands.
-Query to check the Log Shipping related error messages select * from sys.sysmessages where description like '%shipping%' and msglangid = 1033 --Execute it on Primary/Secondary server EXEC xp_readerrorlog 0,1,"Error",Null --Execute it on Primary/Secondary server EXEC xp_readerrorlog 0,1,"Shipping",Null --Execute it on Primary server EXEC xp_readerrorlog 0,1,"Backup",Null --Execute it on secondary server EXEC xp_readerrorlog 0,1,"Restore",Null
SSMS Built In Report
You can use the Log Shipping Status report by right clicking on the Server Name in Management Studio > Reports > Standard Reports > Transaction Log Shipping Status.
Once you click on the Log Shipping Status report, you will get a report as shown below. You can open the status report for the monitoring server, primary server or secondary server. The report will show you the log shipping status (whether it is healthy or not) as well as metadata such as the primary and secondary database names, time since the last backup, last restore file, etc...
System Stored Procedures
You can execute the below Log Shipping System Stored Procedure to monitor log shipping and get detailed information about log shipping.
- This is the how SQL Server generates the Log Shipping Status report by executing sys.sp_help_log_shipping_monitor procedure. This procedure returns the log shipping status (whether it is healthy or not) as well as metadata such as primary and secondary database names, time since last backup, last backup file, last restore file, etc...
- returns all columns from the log_shipping_monitor_primary table for the specified primary log shipping database. It returns server name, database name, time of last backup, backup threshold, threshold alert and history retention period.
- returns all columns from log_shipping_monitor_secondary table for the specified secondary log shipping database. It will return database name, server name, restore threshold, last copied file, time of last copy / restore and history retention period.
Query the MSDB database
You can monitor the log-shipping jobs and errors from the MSDB tables as well.
--Query to list out the Log Shipping Jobs SELECT * FROM msdb.dbo.sysjobs WHERE category_id = 6 --Query to check the job history error messages if any SELECT * FROM [msdb].[dbo].[sysjobhistory] WHERE [message] like '%Operating system error%' --Query to check the Log Shipping errors SELECT * FROM [msdb].[dbo].[log_shipping_monitor_error_detail] WHERE [message] like '%Operating system error%'
Application/System Event Viewer Log
Another option is to check the Application/System Event Viewer Log for any log shipping, backup, restore or system related issues.
- Document your the log shipping configuration information for all servers that are setup for log shipping.
- Create a Job to run the log shipping status report stored procedure and send an email with the details.
About the author
View all my tips