Solved

Alerts being activated prematurely because of restore threshold.

Posted on 2008-06-17
4
1,517 Views
Last Modified: 2012-08-13
I have log shipping setup between two SQL 2005 servers. The logs are backed up and restored on a 12 hour interval. An alert is setup on the restore job that if it fails to send me an email. Once in a while, I'll get an email with the message listed below, but I'll get it 16x. Each time this occurs (maybe 1-2x a month), I review the log shipping history for each job, and each completed successfully. I reviewed the restore job's properties, and the # of retries = 0.

What would cause the email to be sent 16x (each approx. 2 mins apart)?
DATE/TIME:      6/16/2008 7:36:00 PM
 

DESCRIPTION:    The log shipping secondary database Server2.Backup has restore threshold of 1440 minutes and is out of sync. No restore was performed for 1471 minutes. Restored latency is 95 minutes. Check agent log and logshipping monitor information.
 
 

COMMENT:        Log shipping Secondary Server Alert.
 

JOB RUN:        (None)

Open in new window

0
Comment
Question by:awp5379
  • 2
  • 2
4 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21802140
Is it sending one for each database your shipping?

What results do you get when you run this procedure on your monitor server?

sp_help_log_shipping_monitor
0
 

Author Comment

by:awp5379
ID: 21802227
2 records, one for each database that gets shipped. Database #2 is very small and never generates any threshold warnings. Database #1, is pretty large and has tons of daily activity that gets restored. The last_restored_latency was 114. It might be possible that the jobs need to be spread apart a little more (as in backup to copy to restore), but what cause the multiple warning emails?
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21802271
I don't really use the built in alerts for log shipping....here is a proc I wrote that sends alerts and gives me a bit more control over what I see....just put it in a SQL Agent job (make sure you have dbmail setup) and run it whenever you want.
ALTER PROCEDURE sp_LogShippingAlerts

AS

BEGIN

	SET NOCOUNT ON
 

	DECLARE @Msg VARCHAR(MAX)

	DECLARE @dbname varchar(100), @restoretime int, @server varchar(100)

	DECLARE @EmailMessage VARCHAR(1000), @RowCount INT
 

	IF OBJECT_ID('tempdb..#ServerList') IS NOT NULL

	DROP TABLE #ServerList
 

	IF OBJECT_ID('tempdb..#Data') IS NOT NULL

	DROP TABLE #Data
 

	CREATE TABLE #ServerList

	(

		PrimaryServer VARCHAR(50),

		DRServer VARCHAR(50)

	)

	INSERT INTO #ServerList

	(PrimaryServer, DRServer)

	SELECT 'mainserver','backupserver'
 

	CREATE TABLE #Data

	(

		status INT,

		is_primary INT,

		server VARCHAR(255),

		database_name VARCHAR(255),

		time_since_last_backup INT,

		last_backup_file VARCHAR(1000),

		backup_threshold INT,

		is_backup_alert_enabled INT,

		time_since_last_copy INT,

		last_copied_file VARCHAR(1000),

		time_since_last_restore INT,

		last_restored_file VARCHAR(1000),

		last_restored_latency INT,

		restore_threshold INT,

		is_restore_alert_enabled INT

	)
 

	INSERT INTO #Data

	EXECUTE sp_help_log_shipping_monitor
 

	SELECT 

		a.server,

		PrimaryStatus = a.status,

		SecondaryStatus = b.status,

		a.database_name, 

		b.DRServer,

		a.time_since_last_backup,

		a.last_backup_file,

		a.backup_threshold,

		a.is_backup_alert_enabled,

		b.time_since_last_copy,

		b.last_copied_file,

		b.time_since_last_restore,

		b.last_restored_file,

		b.last_restored_latency,

		b.restore_threshold,

		b.is_restore_alert_enabled

	INTO 

		#Temp

	FROM

	(

		SELECT * 

		FROM #Data d

			JOIN #ServerList s ON d.server = s.Primaryserver

		WHERE is_Primary = 1

	) a

	JOIN

	(

		SELECT * 

		FROM #Data d

			JOIN #ServerList s ON d.server = s.DRServer

		WHERE is_Primary = 0

	) b ON a.database_name = b.database_name AND a.Server = b.PrimaryServer

	WHERE 

		(a.Status + b.Status) > 0
 

	SELECT @RowCount = COUNT(*) FROM #Temp
 

	IF @RowCount > 0

	BEGIN
 

		SET @EmailMessage = 'There are ' + CAST(@RowCount AS VARCHAR(5)) + ' database(s) needing attention.'
 

		SET @Msg = '<html><body><table>'

		DECLARE  CursorTemplate CURSOR 

		FAST_FORWARD FOR 	

			SELECT database_name, time_since_last_restore, server FROM #Temp
 

		OPEN CursorTemplate
 

		FETCH NEXT FROM CursorTemplate 

		INTO	@dbname, @restoretime, @server
 

		WHILE (@@FETCH_STATUS = 0)

		BEGIN

			

			SET @Msg = @Msg + '<tr><td>Database ' + @server + '.' + @dbname + ' has not been restored in ' + CAST(@restoretime AS VARCHAR(10)) + ' minutes.</td></tr>'

			FETCH NEXT FROM CursorTemplate 

			INTO	@dbname, @restoretime, @server
 

		END
 

		CLOSE CursorTemplate

		DEALLOCATE CursorTemplate
 

		SET @Msg = @Msg + '</body></html>'
 

		EXEC msdb.dbo.sp_send_dbmail
 

		@recipients=N'emailaddress',

		@body=@Msg, 

		@body_format ='HTML',

		@subject = @EmailMessage,

		@profile_name ='DatabaseMailProfile'

	END

	 

	RETURN(0)
 
 

END

Open in new window

0
 

Author Closing Comment

by:awp5379
ID: 31467924
Good suggestion chapmandew!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql server query from excel 3 57
Microsoft Azure SQL - create a read only user 2 16
Replace Dates in query 14 20
Need SQL that flips  value 5 19
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now